Today's Date in Perl in MM/DD/YYYY format

date, formatting, perl

Solution

You can do it fast, only using one POSIX function. If you have bunch of tasks with dates, see the module DateTime.

use POSIX qw(strftime);

my $date = strftime "%m/%d/%Y", localtime;
print $date;

Problem

I'm working on a Perl program at work and stuck on (what I think is) a trivial problem. I simply need to build a string in the format '06/13/2012' (always 10 characters, so 0's for numbers less than 10). Here's what I have so far: ``` use Time::localtime; $tm=localtime; my ($day,$month,$year)=($tm->mday,$tm->month,$tm->year); ```

Original source