Operating System - HP-UX
1755937 Members
4387 Online
108839 Solutions
New Discussion юеВ

Re: TIME Difference command??

 
Ferdie Castro
Advisor

TIME Difference command??

Hi,

Is there a command in unix which computes time differece . example date/time1 - date/time2.
format of date time is same output of date commmand ex.
Mon Oct 20 14:22:52 EAT 2003
Hope you could help me with this. thanks.
5 REPLIES 5
Ferdie Castro
Advisor

Re: TIME Difference command??

Sorry guys wrong subject header should be system administration.
Rajeev  Shukla
Honored Contributor

Re: TIME Difference command??

I am sorry, there is no such command under unix. But what i can suggest is write a script that converts the time to sec from 1970 then substract both of them which you get in Sec.
RAC_1
Honored Contributor

Re: TIME Difference command??


No such command in unix. May be you can write a script to do that. OR convert dates to to epoc(seconds since 1970) and compare.
There is no substitute to HARDWORK
Graham Cameron_1
Honored Contributor

Re: TIME Difference command??

No standard command but there is a very well known script which allows you to do all kinds of stuff with dates. Search the forums for "caljd".
-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
john korterman
Honored Contributor

Re: TIME Difference command??

Hi,
the attached script can return the seconds since unix calender start (midnight 1970) and a specified time after that. It can be used in two ways: without parameters it uses the date command for finding the current system time and then counts the number of secs since unix cal start and that e.g.:
# ./return_seconds.sh
1066639969

Alternatively, you can specify 7 parameters for time, say for this date:
Mon Oct 20 14:22:52 2003

you need to specify this:
# ./return_seconds.sh 1970 2003 10 20 14 22 52

1066659772

The parameters are described in the script.

The difference:
# echo $(( 1066659772 - 1066639969))
19803

regards,
John K.
it would be nice if you always got a second chance