Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Re: Re: Coverting Date Formats

by grummerX (Pilgrim)
on Mar 05, 2002 at 17:26 UTC ( #149446=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://149446]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2021-12-05 03:03 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (31 votes). Check out past polls.