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


In reply to Re: Using Timestamp to tell if someone is on the site by haukex
in thread Using Timestamp to tell if someone is on the site by htmanning

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.