Page 1 of 1

difference between two timestamp fields

Posted: Wed Apr 16, 2008 6:01 am
by kausmone
Hello again,

I have to compare a timestamp value (lets call it T1) available in a hashed-file with current timestamp (T2). If (T2 - T1) > 4 hours, then write the record to output file.

Is there any function available that will convert timestamps to internal storage format? If I am to use Iconv, I will need to separate the date and time parts, convert them individually to their internal values and compare these. But this will call for some tedious and not-really-readable code. Also, making it bug-free will not be easy...

Is there some way to calculate the epoch, like convert T1 to total number of seconds from 1970, do the same for T2 and compare with 4*60*60 seconds?

Thanks in anticipation!

Rgds,
Kaus

Posted: Wed Apr 16, 2008 6:33 am
by ray.wurlod
Timestamps (in ISO 8601 format YYYY-MM-DD HH:MM:SS) can be compared directly as strings - you don't need any functions at all.