in reply to Using Timestamp to tell if someone is on the site
Hi htmanning,
I often recommend something like DateTime for such calculations, but since in this case you're just subtracting two times to tell if they're more or less than 5 minutes apart and you probably don't need high precision, probably the easiest way is with UNIX timestamps, as huck suggested. In Perl, you can use time to get seconds since the epoch (which on most systems is January 1, 1970, 00:00:00 UTC), and depending on the format of the database column, you can either have the database convert that to a UNIX timestamp, e.g. MySQL has the function UNIX_TIMESTAMP(date), or, if you've stored it in the database as a string, you can use Time::Piece::strptime, POSIX::strptime, or DateTime::Format::Strptime to parse it back into seconds since the epoch - just don't forget to take time zones into account. Then, it's just a simple matter of subtraction of the two values.
Hope this helps,
-- Hauke D
|
|---|