[Brisbane-pm] Convert string to date in Perl

David Bussenschutt David.Bussenschutt at qmtechnologies.com
Tue Jan 30 20:21:47 PST 2007


I use Date::Manip all the time.   it rocks.
see http://search.cpan.org/~sbeck/DateManip-5.44/Manip.pod

use Date::Manip;

$date = ParseDate("25/02/1990 23:48:00");
$delta = ParseDateDelta("+ 6 minutes");
$new = DateCalc($date,$delta); 
# or alternate/shorthand:
$new =DateCalc("25/02/1990 23:48:00","+ 6 minutes"); 

# then output however you like.
print &UnixDate($new,"It is now %T on %b %e, %Y.");

-----Original Message-----
From: brisbane-pm-bounces+david.bussenschutt=qmtechnologies.com at pm.org
[mailto:brisbane-pm-bounces+david.bussenschutt=qmtechnologies.com at pm.org
]On Behalf Of Damian James
Sent: Wednesday, 31 January 2007 2:11 PM
To: Martin Jacobs
Cc: Brisbane Perl Group
Subject: Re: [Brisbane-pm] Convert string to date in Perl


Time::Local

Or roll you own regex, something like:

   my %date;
   $_ = '25/02/1990 23:48:00';
   @date{ qw/ day month year hour minute second/} = m<^(\d\d?)/(\d 
\d?)/(\d{4}) +(\d\d):(\d\d):(\d\d)>;
   $date{ minute } += 6;
   printf "%2d/%2d/%4d %2d:%2d:%2d", @date{ qw/ day month year hour  
minute second/};

Though use the module for maintainability.

Damian

On 31/01/2007, at 2:01 PM, Martin Jacobs wrote:

> Hi all,
>
> I would appreciate some help here.
>
> How do I convert a string to a date?
>
> Here's an example of the string...
>
> 25/02/1990 23:48:00
>
> I want to add on 6 minutes, so that the result is...
>
> 25/02/1990 23:54:00
>
> Thanks in advance.
>
> Regards,
> Martin Jacobs
> Visit my website...
> http://web.mac.com/martin_jacobs1
>
>
> _______________________________________________
> Brisbane-pm mailing list
> Brisbane-pm at pm.org
> http://mail.pm.org/mailman/listinfo/brisbane-pm

_______________________________________________
Brisbane-pm mailing list
Brisbane-pm at pm.org
http://mail.pm.org/mailman/listinfo/brisbane-pm


The message and any attachment is confidential and may be privileged or otherwise protected from disclosure. If you have received it by mistake please let us know by reply and then delete it from your system; you should not copy the message or disclose its contents to anyone.


More information about the Brisbane-pm mailing list