Operating System - HP-UX
1833875 Members
1849 Online
110063 Solutions
New Discussion

Re: date string comparison ?

 
Ian McClement_1
Occasional Advisor

date string comparison ?

Hi
I have two strings with date/times in them
eg. "12:25 12:00" and "12:26 11:00"
is there some form of unix command that will compare two date strings (not necessarily in above format) and give the time between them ?

Any help appreciated

Thanks
Ian
6 REPLIES 6
Pete Randall
Outstanding Contributor

Re: date string comparison ?

Ian,

Search the forums (using the search button on the top left of this page) for Clay's caljd.sh script. It's a wonderful thing and just what you're looking for.

Pete

Pete
Pete Randall
Outstanding Contributor

Re: date string comparison ?

Pete Randall
Outstanding Contributor

Re: date string comparison ?

Sorry Ian, I thought Clay's date hammer would handle that but none of my searches turn up anything of the sort, which makes sense because it deals with Julian dates.

Pete

Pete
Ian McClement_1
Occasional Advisor

Re: date string comparison ?

not bad - but need it to include the time aswell
and give answer in minutes !!
pushing my luck ?
john korterman
Honored Contributor

Re: date string comparison ?

Hi Ian,
if nothing else works, you can try the attached, rather slow script. It can return the number of seconds elapsed since 00:00 Jan 1 of a specified year - and a specified date/time. The script takes seven parameters of which the first is the year on whose midnight Jan 1 the count starts. The remaining six parameters are the year, month, day, hour, minute, and seconds to count up to.
It may sound obscure, an example: show the number of seconds since 00:00 Jan 1 of 2002 and December 25 12:25 same year:

# ./return_seconds.sh 2002 2002 12 25 12 00 00
30974400

Another example:
# ./return_seconds.sh 2002 2002 12 26 11 00 00
31057200

The difference in seconds:
# echo 31057200 - 30974400|bc
82800

And turned into minutes:
# echo 82800 \/ 60|bc
1380

Is that what you want?

regards,
John K.




it would be nice if you always got a second chance
Rick Garland
Honored Contributor

Re: date string comparison ?

There is always perl.
You can do the math on the seconds since epoch then convert back to local time.