SPUG: Date parsing (Was: question)

aaron salo aaron at activox.com
Thu Nov 17 16:30:52 PST 2005

Menton, Stephen wrote:

ParseDate from CPAN module Date::Manip might save you time... If you
can't CPAN it then I'd recommend something long but clear for your own
supportability's sake to match alll the patterns you wish to support.

Another vote for Date::Manip here. Here is an example of something you 
can do with a simple call:

1. Parsing a date from any convenient format

  $date = ParseDate("today");
  $date = ParseDate("1st thursday in June 1992");
  $date = ParseDate("05/10/93");
  $date = ParseDate("12:30 Dec 12th 1880");
  $date = ParseDate("8:00pm december tenth");
  if (! $date) {
    # Error in the date

If you are trying to parse dates as part of trying to put something into 
the outbox, use Date::Manip. Once you use it you will never go back. The 
time you spend reading the doc and examples will be repaid exponentially 
for the rest of your days.


If you are trying to parse dates as an academic exercise for your own 
amusement, and you need some regex examples, open Manip.pm and look 
under the hood. If you don't go that far, just reading the perldoc for 
it will give you uber-understanding of the challenges of date parsing, 
not only between different formats but also things like "every second 
Monday" and what not. Date::Manip very mature, robust, and useful 
module. I recommend it highly.


More information about the spug-list mailing list