0

Bit of an issue with date formatting:

Looking to format this date format " 20130606T083000.093660900 "

2013 06 06 T 08 30 00. 093660900

YYYY MM DD T HH MM SS NANOSECS

Formatting this into Epoch (which I believe is the second time given below without decimals) time would be great, I don't have much experience working with date time and changing them.

My goal is to realistically subtract

20130606T083000.093660900 FROM 1370507400093660900

Any help with even telling me what format the first date is, as it is apparently NOT ISO 8601, thanks!

  • There are libraries that can deal with this, I just tried the R bindings of C++ library CCTZ. It cannot quite handle what you have there -- it needs 2013-06-06T083000.093660900. So depending on what you are most comfortable with in terms of scripting languages you may be able to rely on prior work here. – Dirk Eddelbuettel Aug 18 '22 at 19:33

1 Answers1

0

You can use sed to convert the input to something GNU date can parse, then use GNU date to convert it to the format of the other date. Then compare:

din='20130606T083000.093660900'
dcmp='1370507400093660900'

dstr=$(sed 's/\(..\)\(..\)T\(..\)\(..\)/-\1-\2T\3:\4:/' <<<"$din")
timestamp=$(TZ=UTC0 date +%s%N --date="$dstr")

diff=$(( dcmp - timestamp ))

# diff is now: 0

I have forced timezone to avoid localisation concerns.

jhnc
  • 11,310
  • 1
  • 9
  • 26