My first question is what timezone is the time in. If it is a TIMESTAMP field, it is in effect stored as a UTC time but whenever you select or set it it is converted to the timezone of your connection (which defaults to your server default timezone, but some client libraries silently set for you to something else). If it is a DATETIME field, it is stored in whatever timezone you provide it in (and if that is a timezone that uses daylight saving, some values will be ambiguous). For those reasons I highly suggest always using DATETIME and always storing in UTC (and avoiding all functions that use the connection timezone, like NOW(), using e.g. UTC_TIMESTAMP() instead).

Assuming for a moment it is in your local timezone, and by "without considering time" you mean on or after midnight of 20 days ago in your local timezone, you can just do:

my $last_update = '2025-06-30 14:40:26'; if ($last_update ge (Time::Piece->localtime - 20*24*60*60)->truncate(' +to' => 'day')->strftime('%F')) {
But you might have meant on or after midnight of 19 days ago.

In reply to Re: MySQL datetime by ysth
in thread MySQL datetime by joyfedl

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.