[prog] Perl dates

Rasjid Wilcox rasjidw at openminddev.net
Mon Feb 17 20:25:38 EST 2003


On Mon, 17 Feb 2003 12:30 am, Sue Stones wrote:
> I have been trying to figgure out how to get a date in the form "mmyyyy"
> but haven't succeeded. I can get a beutifully formatted string using the
> unix `date` command, but that is not what I want this format to name log
> files.
>
> The only perl book that i have at the moment is "perl in 24 hrs" ~ or
> something to that effect.  I may have to get a better book, when I can
> afford it.

The date function can do pretty much any formatting you want.  see 'man date'.  
For your example,

my $a = `date \"+%m%Y\"`;

should do what you want.

However, could I suggest naming your files with "yyyymm" (ie, +%Y%m) instead.  
That way, assuming that they all have the same prefix, viewing in 
'alphabetical' sorted order will also be in date order.

Alternately, use localtime() as others have suggested, for a pure perl 
solution.

Cheers,

Rasjid.


-- 
Rasjid Wilcox
Canberra, Australia (UTC +11 hrs)
http://www.openminddev.net




More information about the Programming mailing list