Obviously, the first suggestion is to do it in the database. But if you have good reasons not to do that then consider using the core module Time::Piece:
use strict; use warnings; use Time::Piece; use Time::Seconds; use Test::More tests => 2; my $last_update = ('2025-06-30 14:40:26'); cmp_ok days_since ($last_update), '<', 20, "$last_update is less than +20 days ago"; $last_update = ('2025-05-30 14:40:26'); cmp_ok days_since ($last_update), '>', 20, "$last_update is more than +20 days ago"; sub days_since { my $stamp = shift; my $tp = Time::Piece->strptime (substr ($stamp, 0, 10), '%Y-%m-%d' +); my $dayssince = (localtime() - $tp) / ONE_DAY; }
You might want to use gmtime instead of localtime depending on how you are storing the times in your DB.
🦛
In reply to Re: MySQL datetime
by hippo
in thread MySQL datetime
by joyfedl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |