Alex Rivera | Logout

how to convert a date HH: MM: SS in second with bash?

Asked 2013-05-07T08:31:46.113
12

How to convert a date HH: MM: SS in second with bash?

Knowing that this is a date that I recovered in a file so I can't take it in another format.

I have two variables $DateStart and $DateEnd and i would like the difference between both.

Edit
Report

1 Answer

19
date +%s

returns the current datetime in seconds since 1970-01-01 00:00:00 UTC

if you want to get a given datetime in seconds since 1970-01-01 00:00:00 UTC, for example:

kent$  date -d"2008-08-08 20:20:20" +%s
1218219620

to get diff in seconds, you just get the two dates in seconds, and do a s1-s2

answered 2013-05-07T08:37:05.867

Your Answer