I`m trying to convert a timestamp to an ISO8601 datetime-string.
E.g.
timestamp_as_iso8601_date=$(date --iso-8601=ns -d #1606982602015489365)
The timestamp is fairly long, with nanoseconds precision, and when I use the full timestamp it returns the following error:
date: time ‘1606982602015489365’ is out of range
The expected result should be: 2020-12-03T09:03:22,015489300+01:00
When I cut the timestamp to this: 1606982612 the error is gone but I loose information!
Is there any way to convert the timestamp without losing the milliseconds information?
Insert a comma:
date --iso-8601=ns -d #1606982602.015489365
Related
I have the following dataframe:
The column Time is a string and I want to convert it either to timestamp or datetime formats. However, when I run df['Time'] = pd.to_datetime(df['Time']), I always get an error
OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1-01-01 08:53:30
Are you sure you are getting the right column and values. Because running
time = pd.to_datetime("13:30:35.805")
Gives
Timestamp('2020-04-20 13:30:35.805000')
as output as expected.
If you can't solve the problem with pandas directly you can always manually split the string in hours, minutes and seconds with
h, m, s = map(float, x.split(':'))
And use those values to create a timestamp
I am trying to create a timestamp string:
TS=$(date -d "today" +"%Y_%d_%m_%H%M%S")
echo "TS = $TS"
But I need it to be in UTC+3. The man pages on date does not show that as an option and I don't want to modify the OS locale.
I have tried:
$ date -d "today" +"%Y_%d_%m_%H%M%S +0300"
2020_16_04_090342 +0300
$ date -d "today" +"%Y_%d_%m_%H%M%S +0400"
2020_16_04_090347 +0400
So seems it has no effect. Also the string should NOT contain the offset, should just be:
2020_16_04_120347
Any suggestions?
man date
DATE STRING
The --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday". A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the info documentation.
date -d "today" +"%Y_%d_%m_%H%M%S +0300"
I am having this data and try to convert the string date to datetime format. and I have this time data does not match format error.
Date=stock['Trddt'].values
datetime.datetime.strptime(Date[0], "%y.%m.%d")
and it return this error:
ValueError: time data '2015/11/23' does not match format '%y.%m.%d'
Try datetime.datetime.strptime(Date[0], "%Y/%m/%d").
%y matches years without century, but you have years with century, so you need capital %Y.
I have a complex date string being read from a csv file. The format is unable to be processed by Oracle's TO_DATE function. Looking for an efficient method to break this string apart and return a date object, to insert into a DATE column. The suggested option of using TO_DATE with 'DD-MON-YY HH.MI.SS AM' does not work. Not variation of this will break up this particular string. Hence the need for a custom function. I have also tried with the 'HH.MI.SS.SSSSS AM' format which also does not work. I have found that if I drop the fractional seconds, it will work. If I run a regex to drop that portion, it should convert as expected.
The string is formatted as: 21-OCT-04 01.03.23.966000 PM
My initial thought is to break up by space first, resulting in three sub strings.
Then break the first substring by - and the second by ., and load the resulting pieces into a DATE object directly.
Is there a better method I could use?
Thank you, Allan
Use what you have, which is a timestamp literal, to create a timestamp, and then cast it "as date":
select
cast(to_timestamp('21-OCT-04 01.03.23.966000 PM', 'dd-MON-rr hh.mi.ss.ff AM') as date) dt
from dual;
DT
----------------------
2004/10/21 01:03:23 PM
(The output format depends on my specific session NLS_DATE_FORMAT, which I actually changed for this illustration to 'yyyy/mm/dd hh:mi:ss AM'.)
I have a row in excel with the following data: 1271664970687 (I think it's the number of milliseconds from 1970...).
I would like to have addition row that will show it as date/time.
Converting your value in milliseconds to days is simply (MsValue / 86,400,000)
We can get 1/1/1970 as numeric value by DATE(1970,1,1)
= (MsValueCellReference / 86400000) + DATE(1970,1,1)
Using your value of 1271664970687 and formatting it as dd/mm/yyyy hh:mm:ss gives me a date and time of 19/04/2010 08:16:11
See Converting unix timestamp to excel date-time forum thread.