in reply to Re: Re: Coverting Date Formats
in thread Coverting Date Formats
I'd have to concur with gellyfish on this one -- Date::Manip is probably overkill in this instance. I think rolling your own is the best solution in this case. You should be able to convert it to the desired format with a simple regex and a hash to handle the month abbreviations:
That regex can probably be polished up a bit, but it should suit your purposes. If you do want to go ahead with Date::Manip, something like this should work:#!/usr/bin/perl -w use strict; $_ = "[27/Feb/2002:05:05:51 -0800]"; my %months = ( Jan => '01', Feb => '02', # ... Dec => '12', ); m|\[(\d*)/(\D*)/(\d*):(\d*:\d*:\d*) [^\]]*\]|; print "$3-$months{$2}-$1 $4";
If you decide to use either implementation, please test them thoroughly before use.#!/usr/bin/perl -w use strict; use Date::Manip; $_ = "[27/Feb/2002:05:05:51 -0800]"; s/\[|\]//g; # Strip the brackets for Date::Manip $_ = ParseDate($_); s/://g; # Strip the colons for MySQL print;
-- grummerX
|
|---|