Date and Time in Perl
Introduction
Many newcomers to Perl ask how to properly handle, process and manipulate dates and times in Perl. The proper answer is that while Perl has basic facilities for this in perlfunc and the POSIX module, one should use a good date-and-time module from CPAN. This page aims to lead people in the right direction.
CPAN Distributions for Date and Time Manipulation
DateTime
The DateTime CPAN distribution is a highly recommended module for handling dates and times. Here are some useful helper packages for it:
- DateTime-Format-Strptime - parses dates in arbitrary formats.
- DateTime-Format-W3CDTF, DateTime-Format-Atom and other "DateTime-Format-" modules - useful for parsing and formatting dates using various standard date formats.
- DateTime-Format-Natural allows one to convert dates in human-time to a DateTime object.
- Time-Duration converts a duration (in seconds, which can be calculated from a DateTime object) into a human readable expression of it (exact or rounded). Like "10 minutes ago", "1 hour ago", etc.