Hive timestamp type wrong - hive

Hi I have 10 timestamp data of "2016-08-12 16:00:00",I use "SparkSql in Java to create a DataSet and insert overwrite data into Hive. When I read all 10 data, I found some of it are "2016-08-12 16:00:00" and others are "2016-08-12 04:00:00".I think it may because Hive uses 12-hour timestamp as 16 is 4 in afternoon,but the problem is they are not consistent.
I can sure that in Dataset ,timestamps are all 2016-08-12 16:00:00
How can I understand this problem and solve it?

It uses 24 Hours format. so both the date are in correct format.first one is 4 am and another one is 4 pm. and if you are writing from external system ,use 'yyyy-MM-dd HH:mm:ss' format instead of 'yyyy-MM-dd hh:mm:ss a' format.

Related

timestamp difference in bigquery with date

I have used Dataiku to transfer 40 GB of data from snowflake to big query. Somehow timestamp value changed my dates completely
Instead of 2021-06-30 00:00:00 UTC the copied timestamp value is 2021-06-29 22:00:00 UTC
I am looking for a bigquery solution to cast this into the correct timestamp as loading the data again is not possible.
Can someone help please? Thanks
found the solution
SELECT TIMESTAMP_ADD(Day_Sts, INTERVAL 120 MINUTE) AS Day_Sts,* except (Day_Sts)

date_format function in Hive gives wrong output

I am trying to format date and time down to millis as in the following code:
date_format(date_and_time, 'YYYY-MM-dd HH:mm:ss.SSS') as date_and_time
However if I am querying the date_and_time value prior to formatting and after formatting I get
two different results:
2021-02-03 04:09:14.367 vs 2021-12-31 20:54:20.504
Normally I should get same 2021-02-03 04:09:14.367, am I doing something wrong?
This example does have initially milliseconds values but I have some data in the dataset that don't.
Thank you
solved by formatting with 'yyyy-MM-dd HH:mm:ss.SSS'

convert date to midnight in hive

I want to truncate a specific date to midnight time in hive.
I have tried the following below, but it puts 12 hour time instead of 00.
date_format(MIN(date_and_time), 'yyyy-MM-dd hh:00:00.000')
Result obtained
2021-11-03 12:00:00.000
Any suggestions on that?
Thank you
Use HH for a 24-hour clock:
date_format(MIN(date_and_time), 'yyyy-MM-dd HH:00:00.000')

Hive date format handling

I am handling JSON data containing a date as per this example 'MON 2014-01-03 13:00:00 +GMT0000'
I need to compare records on date.
Is it best to load as strings and manipulate as and when required?
A requirement will be to select the highest and lowest dates for a particular criteria, and calculate the difference in seconds.
Thanks for looking.
Best solution for your problem is to use unixtimestamp (seconds since standard epoch of 1/1/1970)
Following is an example query, as to how you parse the timestamp-strings to unixtimestamp.
select unix_timestamp(REGEXP_REPLACE('MON 2014-01-03 13:00:00 +GMT0000','GMT',''),
"EEE yyyy-MM-dd HH:mm:ss Z") as unixtime from reqtable;
You will have more details here https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-DateFunctions
Also you should take a look into Java SimpleDateFormat to match the exact timestamp string pattern.

How to save date into 24 hours format in oracle

I am new to Oracle, and I need to save date and time in an Oracle database.
I am using time stamp as datatype for row. But now my problem is it saves date and time in 12 hours format like this 17/11/2011 10:10:10 PM.
But I need it in 24 hours format like 17/11/2011 22:10:10. I didn't understand the results that Google search result provided. Can any one please help me by posting some code.
Oracle always stores timestamps (and dates) in a packed binary format that is not human readable. Formatting is done only when a timestamp (or a date) is converted to a string.
You can control the formatting of your output by coding an explicit to_char. For example
SELECT to_char( your_timestamp_column, 'DD/MM/YYYY HH24:MI:SS' )
FROM your_table
Oracle stores timestamps in an internal format (with a default representation).
You can customize this representation on output like with the to_char() function.
For input (into the database) you can use to_date().