[Brisbane-pm] Convert string to date in Perl

Damian James djames at thehub.com.au
Tue Jan 30 20:40:09 PST 2007


Actually looking back over some old code and comparing pod, it looks  
like I was actually thinking of Date::Parse. So this would be:

use Date::Parse;
my dt = str2time('25/02/1990 23:48:00');
$dt += 6 * 60;
etc

Date::Manip wasn't around when I worked with dates in any significant  
way last. It looks like a better approach.

And yeah, obviously what I wrote below doesn't calculate dates  
correctly :) Off-the-cuff untested example code which clearly would  
end up in production...


On 31/01/2007, at 2:11 PM, Damian James wrote:

> 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



More information about the Brisbane-pm mailing list