Re: How to convert number of seconds in to date OR vice versa (140 Views)
Reply
Trusted Contributor
Manju Kampli
Posts: 224
Registered: ‎07-01-2000
Message 1 of 5 (140 Views)
Accepted Solution

How to convert number of seconds in to date OR vice versa

Dear Friends,

I am trying to write some scripts for ITO and see the date and time of the message received and compare it with the local time. if the message is sitting there for more than 30 mins I want to generate some alerts for operatiors.

This date filed in the IT/O database is in the form of seconds. It stores the date in number of seconds Since 1st Jan 1970. It means the current entry will be (60 * 60 min * 24 Hr * 365 days* 31 yrs ) seconds OR something similar
.
looks strange isn't it.... Well.. IT/O must be running some commands to calculate this seconds to date before displaying it on the message browser.

I want to know how can convert these seconds in to date so that I can compare it with current date and time. what commands I can use to get the current date in to number of seconds OR seconds available in the database in to date format

Thanks for your time

Cheers,
Manju
Never stop "LEARNING"
Please use plain text.
Occasional Visitor
David Sullivan_1
Posts: 2
Registered: ‎05-15-2001
Message 2 of 5 (140 Views)

Re: How to convert number of seconds in to date OR vice versa

Hello!

Check out this URL http://www.oase-shareware.org/shell/links/index.html#archives scan for timeinseconds

Hope it helps!

Dave
Please use plain text.
Occasional Visitor
David Sullivan_1
Posts: 2
Registered: ‎05-15-2001
Message 3 of 5 (140 Views)

Re: How to convert number of seconds in to date OR vice versa

Sorry, wrong url...
http://www.zipworld.com.au/~cs/scripts/
scroll down to timeinseconds...


Dave
Please use plain text.
Respected Contributor
Herve BRANGIER
Posts: 215
Registered: ‎07-06-2000
Message 4 of 5 (140 Views)

Re: How to convert number of seconds in to date OR vice versa

Hi,

You can do that with a small part of C code (
see at the end to have an example). You can
use some C functions to do this (man ctime to
have all informations needed).
Compile with : cc
And start with : ./a.out

#include

main (nargs,args)
int nargs;
char ** args;
{
/* Here you translate args 1 : first time entered in seconds */
time_t my_time1 = atoi (args[1]);
/* Here you translate args 2 : second time entered in seconds */
time_t my_time2 = atoi (args[2]);

/* Now you can display dates using local time parameters like timezone,
summer time,... */
printf ("\nThe first date in parameter is : %s\n",asctime (localtime (&my_time1)));
printf ("\nThe second date in parameter is : %s\n",asctime (localtime (&my_time2)));

}


Bye,

Herve

Please use plain text.
Honored Contributor
Robin Wakefield
Posts: 861
Registered: ‎06-14-1998
Message 5 of 5 (140 Views)

Re: How to convert number of seconds in to date OR vice versa

perl -e 'print time,"\n"'

will display the # secs since 1/1/70. Then use "bc" or your favourite unix number crunching command to work out the difference from your ITO figure.

Robin.
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation