CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
date conversion

 



anderst
New User

Mar 18, 2009, 7:38 AM

Post #1 of 3 (805 views)
date conversion Can't Post

Hi!

I need help with date conversion, I need a perl-script that transform
Wed Mar 28 00:00:00 GMT+02:00 2007
to
2007-03-28

I have tried to use perl modules Date::Manip and Date::Calc, but no succes so far. Maybe I am doing it the wrong way.


// A


FishMonger
Veteran / Moderator

Mar 18, 2009, 7:51 AM

Post #2 of 3 (802 views)
Re: [anderst] date conversion [In reply to] Can't Post

There are several approaches, here's one of the more common.


Code
my %months = ( Jan => '01', Feb => '02', Mar => '03', Apr => '04', 
May => '05', Jun => '06', Jul => '07', Aug => '08',
Sep => '09', Oct => '10', Nov => '11', Dec => '12'
);

my $datestamp = 'Wed Mar 28 00:00:00 GMT+02:00 2007';

my ($month, $day, $year) = (split(/\s/, $datestamp))[1,2,-1];

print "$year-$months{$month}-$day";



(This post was edited by FishMonger on Mar 18, 2009, 7:52 AM)


KevinR
Veteran


Mar 18, 2009, 11:58 AM

Post #3 of 3 (797 views)
Re: [FishMonger] date conversion [In reply to] Can't Post

This makes at least 3 forums with this same question, and so far no replies from the OP.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives