Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I need some help with reformatting dates, I got a script that gets results for the Whois database and I need to check the expiration dates. The dates or formatted in different ways. Here is a list of expiration dates
xmas.com : 08-Nov-2007 
---------------------------------------------------------------------------------
jacket.com : 30-Jul-2006.
---------------------------------------------------------------------------------
shows.com : 2006-12-20
---------------------------------------------------------------------------------
item.com : 22-Aug-2009.
---------------------------------------------------------------------------------
book.biz : Tue Jun 03 23:59:59 GMT 2008
---------------------------------------------------------------------------------
rebound.com : 2006-08-04 14:05:00.0 
---------------------------------------------------------------------------------
video.us : Sun Apr 23 23:59:59 GMT 2006
---------------------------------------------------------------------------------
bookshop.com : 2007-10-25 00:00:00 UTC
---------------------------------------------------------------------------------
cooking.info : 07-Aug-2006 18:57:38 UTC 
---------------------------------------------------------------------------------
laptops.info : 13-Jul-2006 19:40:41 UTC 
---------------------------------------------------------------------------------
baths.com : Wed, Oct 04, 2006
---------------------------------------------------------------------------------
wanted.com : 11 Nov 2006 17:49:48 
---------------------------------------------------------------------------------
robot.info : 13-Jul-2006 19:19:40 UTC 
---------------------------------------------------------------------------------
je.com : 26-Jan-2007.
---------------------------------------------------------------------------------
tortillas.com : 11-Oct-2006 
---------------------------------------------------------------------------------
organicstore.com : 19-JUN-06
---------------------------------------------------------------------------------
service.biz : Sun Mar 26 23:59:59 GMT 2006
---------------------------------------------------------------------------------
champagne.info : 15-Aug-2006 20:37:13 UTC 
---------------------------------------------------------------------------------
sportsbars.com : 04-03-2006
---------------------------------------------------------------------------------
blue.com : 29-Oct-2006.
---------------------------------------------------------------------------------
housewarming.com : 03 Sep 2014 14:53:51 
---------------------------------------------------------------------------------
arrows.com : 2006-11-25 00:00:00.0 
---------------------------------------------------------------------------------
prolink.com : 21 Jul 2006 00:00:00 
---------------------------------------------------------------------------------
photos.net : 10-21-2006
---------------------------------------------------------------------------------
agencies.com : 2006-04-22
---------------------------------------------------------------------------------
micheals.com : 12 Jul 2006 21:46:01 
---------------------------------------------------------------------------------
staffordshire.com : 11 May 2011 14:26:08 
---------------------------------------------------------------------------------
snowman.com : 2007-01-10 14:22:18.0 
---------------------------------------------------------------------------------
loc.com : 21-Oct-2009.
---------------------------------------------------------------------------------
apartment.info : 13-Jul-2006 19:26:39 UTC 
---------------------------------------------------------------------------------
dvd.us : Sat Apr 23 23:59:59 GMT 2011
---------------------------------------------------------------------------------
godfather.com : Feb 22, 2006
---------------------------------------------------------------------------------
discountstore.com : 10-22-2006
---------------------------------------------------------------------------------
gunfight.com : May 6 2006.
---------------------------------------------------------------------------------
platinum.biz : Sun Mar 26 23:59:59 GMT 2006
---------------------------------------------------------------------------------
ucsd.com : 02-Oct-2006
---------------------------------------------------------------------------------
cattle.com : 28-Jul-2006.
---------------------------------------------------------------------------------
guns.biz : Sun Mar 26 23:59:59 GMT 2006
---------------------------------------------------------------------------------
designerclothes.com : Tue, Nov 21, 2006
---------------------------------------------------------------------------------
nanotech.us : Sun Apr 23 23:59:59 GMT 2006
---------------------------------------------------------------------------------
mortuaries.com : 01-23-2007
---------------------------------------------------------------------------------
chosen.com : 2006-06-25 
---------------------------------------------------------------------------------
imageconsultants.com : 20-Jan-07 
---------------------------------------------------------------------------------
musket.com : 2011-04-04 06:54:38.0 
---------------------------------------------------------------------------------
safesale.com : 2006-10-26
---------------------------------------------------------------------------------
outdoorwear.com : 2014-05-30 PST (0)
---------------------------------------------------------------------------------
huntingknife.net : 29-Mar-2006 
---------------------------------------------------------------------------------
glossygifts.com : 24-Dec-2006.
---------------------------------------------------------------------------------
Now my question. Is there a way or program that can distinguish and reformat them.

Replies are listed 'Best First'.
Re: Date Help
by ikegami (Patriarch) on Jan 04, 2006 at 19:30 UTC
Re: Date Help
by wazzuteke (Hermit) on Jan 04, 2006 at 19:29 UTC
    I've found the module Date::Calc to be usefull in such situations.

    Check out CPAN for more info on it.

    At a first glance, it looks as though you might want one of two functions that are pre-built into the mod. I'd recommend:
    use Date::Calc qw( Decode_Date_EU Decode_Date_US );
    For a good portion of the dates, although there may be more that would be better suited for you to use.

    ---hA||ta----
    print map{$_.' '}grep{/\w+/}@{[reverse(qw{Perl Code})]} or die while ( 'trying' );
Re: Date Help
by Happy-the-monk (Canon) on Jan 04, 2006 at 20:43 UTC

    Is there a way or program that can distinguish and reformat them.

    To distinguish, you may use regular expressions as explained in perldoc perlre or perlrequick.

    To reformat them, see the answers to a question asked earlier today: Best way to compare date strings.

    Cheers, Sören

Re: Date Help
by saberworks (Curate) on Jan 04, 2006 at 21:13 UTC
Re: Date Help
by ambrus (Abbot) on Jan 05, 2006 at 12:08 UTC

    The CPAN module Date::Manip parses most of these dates, but there are some (namely those of format mm-dd-yyyy and 2014-05-30 PST (0)) which it can't parse.

    Here's an example, of course you can use any other output format than the "%c" I'm using here.

    use warnings; use Date::Manip; while (<DATA>) { if (/(.*: )(.+)/ and defined($d = UnixDate($2, "%c"))) { print $1, $d, "\n"; } else { print $_; } } __DATA__ xmas.com : 08-Nov-2007 ---------------------------------------------------------------------- +--------- jacket.com : 30-Jul-2006. ---------------------------------------------------------------------- +--------- shows.com : 2006-12-20 ---------------------------------------------------------------------- +--------- item.com : 22-Aug-2009. ---------------------------------------------------------------------- +--------- ...