in reply to How do I find today's date?

If you just need a timestamp string, ala "Wed Mar 22 10:56:43 PST 2000" you can just: print scalar localtime() ; -Ducky

Replies are listed 'Best First'.
Re: Answer: How do I find today's date?
by SkipHuffman (Monk) on Sep 19, 2005 at 12:18 UTC

    It sure would be nice to expand this to include how to find some other simple dates:

    • Yesterday
    • tomorrow
    • same time last week
    • same time next week
    • same day next month
    • same day last month
    • same day last year
    • same day next year.

    Skip

      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";

      🦛