Having a difficult time parsing this particular expression:
'2021-01-06 01:16:04.0880000 +00:00'
I have tried the below whole consulting the docs for timestamp:
select parse_timestamp('%Y-%m-%d %H:%M:%S.%E*S %Ez', '2021-01-06 01:16:04.0880000 +00:00')
Any help would be appreciated, thank you
The %E*S also includes the seconds (%S) so you can use the following instead:
SELECT PARSE_TIMESTAMP('%Y-%m-%d %H:%M:%E*S %Ez', '2021-01-06 01:16:04.0880000 +00:00')
-- Output: 2021-01-06 01:16:04.088 UTC
Related
What I need to do is pretty simple.
I just need to update a DATE field in SQL to a PM time.
Only thing is, if I use the TO_DATE function to update to an AM time, no problem...
TO_DATE('2021-09-30 11:00:00', 'YYYY-MM-DD HH:MI:SS')
However if I try to do the same thing to set to a PM time using military time...
TO_DATE('2021-09-30 23:00:00', 'YYYY-MM-DD HH:MI:SS')
It says that the hour has to be between 1 and 12.
Any suggestions?
Thanks
According to the Oracle documentation, in order to convert a time in 24 hour format, you need to use HH24. When you use just HH, Oracle assumes the time to be in AM/PM format, i.e. that the number must be between 1 and 12.
So you need to change your code to the following
TO_DATE('2021-09-30 23:00:00', 'YYYY-MM-DD HH24:MI:SS')
Refer to this db<>fiddle
I am trying to parse and convert date time using below statement. But, its producing wrong result.
SELECT
SAFE.PARSE_TIMESTAMP('%m/%d/%Y %I:%M %p', '9/6/21 7:22 AM',"US/Central")
Also, how to handle daylight savings with bigquery?
BigQuery does handle DST. It might help if you parsed your date in the modern era. I also tend to use city names to be sure I'm getting the local time:
SELECT SAFE.PARSE_TIMESTAMP('%m/%d/%y %I:%M %p', '9/6/21 7:22 AM', "US/Central"),
SAFE.PARSE_TIMESTAMP('%m/%d/%y %I:%M %p', '9/6/21 7:22 AM', 'America/Chicago')
Note that this produces a date this year rather than in the year 21 AD.
After a good research and failing to get the required solution, I am posting the question here.
Problem: Unable to convert timestamp '1541107867006' to required date time format in SAP Scripted Calculation View.
Tried the below code and SAP functions but they work for other formats and not this specifically.
SELECT TO_TIMESTAMP (ADD_SECONDS( '1970-01-01 00:00:00', '1541107867006')) TIMESTAMP,
TO_DATE (ADD_SECONDS( '1970-01-01 00:00:00', '1541107867006')) DATE,
TO_TIME (ADD_SECONDS( '1970-01-01 00:00:00', '1541107867006')) TIME
from DUMMY
Can you please help with this? Really appreciate your response!
Thanks
Supriya
This worked for me.
TO_CHAR(ADD_SECONDS(TO_TIMESTAMP('1970-01-01 00:00:00'), cast('1541107867006' as bigint)/1000),'mm/dd/yyyy')
The constant '1541107867006' is not in seconds, but in milliseconds.
Try
SELECT ADD_SECONDS(TO_TIMESTAMP('1970-01-01 00:00:00'),
cast('1541107867006' as bigint)/1000) as "Timestamp"
from DUMMY;
or, because some casts are implicit:
SELECT ADD_SECONDS('1970-01-01 00:00:00',
cast('1541107867006' as bigint)/1000) as "Timestamp"
from DUMMY;
It's easier when the (numeric) Unix timestamp is given as a BIGINT right away:
SELECT ADD_SECONDS('1970-01-01 00:00:00', 1541107867006 / 1000) as "TimeStamp"
from DUMMY;
I'm trying to convert the following command:
to_char(to_date('01/01/1970 00:00:00', 'MM/DD/YYYY HH24:MI:SS')+((1442998800)/( 60 * 60 * 24 )+(180/1440)),'DD/MM/YYYY HH24:MI:SS')
But with no success, any help is greatly appreciated
Many thanks
Try this:
DECLARE #Input int = 1442998800
SELECT dateadd(second, #Input, '1970-01-01 03:00:00')
see fiddle here.
Explenation: it's clear that the input is the number of seconds since a specific date - turns out that date is January first, 1970, at 3 am.
This works for me:
SELECT FORMAT(DATEADD(SECOND,1442998800,'1970-01-01'),'dd/MM/yyyy hh:mm:ss')
In words' it adds 1442998800 seconds to 1970-01-01 and formats it the way you decsribed. Give it a try ;-)
I have a situation where I need to convert the datetime value stored as string to Timestamp:
I am using oracle database
This actually works for me select TO_DATE('11-27-2013 21:28:41', 'MM-DD-YYYY HH24:MI:SS') from dual;
But my date value now is diffent from the above:
select TO_DATE('Sunday 6/1/2014 8:00AM', 'MM-DD-YYYY HH24:MI:SS') from dual; - failed. I have 'Sunday' inside my date.
You have to specify a correct format mask to the TO_DATE function. See a full list of format masks along with documentation for the function here: http://www.techonthenet.com/oracle/functions/to_date.php
You can correct your problem by:
SELECT TO_DATE('Sunday 6/1/2014 8:00AM', 'DAY M/D/YYYY HH:MIAM') FROM DUAL;
Try using the correct format. I think this will work:
select TO_DATE('Sunday 6/1/2014 8:00AM', 'DAY MM/DD/YYYY HH:MI AM')
Here is a SQL Fiddle.
The following seems to work fine:
SELECT TO_DATE('Sunday 6/1/2014 8:00AM', 'DAY MM/DD/YYYY HH:MIAM') FROM DUAL
Share and enjoy.