in reply to Re: Re: Coverting Date Formats
in thread Coverting Date Formats

MySQL can handle the second format just fine. The first format will give you some problems. You're going to have to do some kind of manipulation to it before you do an insert.

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:

#!/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";
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; 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;
If you decide to use either implementation, please test them thoroughly before use.

-- grummerX