I could do [the sensible thing], but I'd rather a perlish way to do it.

If you're dead-set against doing the comparison in SQL, you could use DateTime::Format::MySQL to convert the dates to DateTime objects, ->add(days=>1), and compare to DateTime->now() using DateTime->compare(). This will not perform as well (in terms of execution time) as doing it in SQL, however. It would be one thing if you were occasionally checking a date this way, or if you were doing more complex things with the dates and needed the extra functionality DateTime provides, but if all you're doing is looping through all the rows of a table and getting a list of the ones where a certain field is less than a day ago, throwing a WHERE clause into the query seems like a much better solution to me. Really, it does. Even if you're mostly not directly interacting with the DB at the SQL level (e.g., if you're using an abstraction layer like Class::DBI), you still could use a single SQL query just to build a list of record IDs that you want and then map those over to your abstraction-layer objects.


In reply to Re: Detecting 1 day ago by jonadab
in thread Detecting 1 day ago by Anonymous Monk

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.