The core modules Time::Piece and Time::Seconds make this very easy.
#!/usr/bin/env perl use strict; use warnings; use Time::Piece; use Time::Seconds; my $now = localtime; print "Today is $now\n"; my $tp = $now - ONE_DAY; print "Yesterday was $tp\n"; $tp = $now + ONE_DAY; print "Tomorrow will be $tp\n"; $tp = $now - 7 * ONE_DAY; print "A week ago was $tp\n"; $tp = $now + 7 * ONE_DAY; print "Next week will be $tp\n"; $tp = $now->add_months (-1); print "A month ago was $tp\n"; $tp = $now->add_months (1); print "Next month will be $tp\n"; $tp = $now->add_years (-1); print "A year ago was $tp\n"; $tp = $now->add_years (1); print "Next year will be $tp\n";
🦛
In reply to Re^2: Answer: How do I find today's date?
by hippo
in thread How do I find today's date?
by vroom
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |