1829183 Members
2562 Online
109986 Solutions
New Discussion

Timestamp

 
SOLVED
Go to solution
Ryan Ma
Frequent Advisor

Timestamp

How can I generate a timestamp from date/time?

For example
timestamp 9800370710
generated from 2000-Dec-18 14:20:34

I want to get a timestamp for current date/time in order for comparasion of job execution time.
9 REPLIES 9
Sridhar Bhaskarla
Honored Contributor
Solution

Re: Timestamp

I am not sure if there is a command to get what you want. Compile this small c program and see if this is what you are looking for.

#include
#include

main()
{
time_t t;

time(&t);

printf("%d", t);
}

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Robin Wakefield
Honored Contributor

Re: Timestamp

Hi Ryan,

To get the current timestamp:

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

Rgds, Robin.
Klaus Crusius
Trusted Contributor

Re: Timestamp

For job execution time there is a wonderful command "timex" which shows you the time consumption of a process'es lifetime.

If you needed improved accuracy (clock ticks vs. seconds) use the gettimeofday function replacing the time function in the C-program.

Klaus
There is a live before death!
Ryan Ma
Frequent Advisor

Re: Timestamp

Klaus,

Sorry, I am afraid I have misleaded you.

I want to compare different finish time of jobs so "timex" command cannot be used.
Bill Thorsteinson
Honored Contributor

Re: Timestamp

Three options:

- Use gnu date with the %s formatting option
date +%s

- Use perl like Robin suggested
perl -e 'print time();'

- Use a simple program such as Sridhar presented.
Ryan Ma
Frequent Advisor

Re: Timestamp

Bill,

The first option doesn't work.
# date +%s
date: bad format character - s
# date +"%s"
date: bad format character - s

It works using perl or writing a C program so I will not try Sridhar.
someone_4
Honored Contributor

Re: Timestamp

Hi .. Maybe Im a little late ..
we use.
#date +%m%d%H%M
Gives you
09132138
From Thu Sep 13 21:38:13 CDT 2001

In a job redirect your output to file.txt
With this at the end
stamp=`date +%m%d%H%M`
cp file.txt file.txt.$stamp
and it will look like this
file.txt.09132138

Richard
someone_4
Honored Contributor

Re: Timestamp

OHH if you want seconds at the end
#date +%m%d%H%M%S
Gives you
0913214619
from ..
Thu Sep 13 21:46:19 CDT 2001

Richard
Ryan Ma
Frequent Advisor

Re: Timestamp

Richard,

I have thunk of your idea but I find that it does not suit my need.

The reason is that I can't find the difference of time between two timestamp made from date +%m%d%H%M%S.

If using other method to obtain the timestamp, I can get the difference of seconds.