Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Date::Manip and date

by Athanasius (Archbishop)
on Jul 09, 2015 at 10:20 UTC ( [id://1133929]=note: print w/replies, xml ) Need Help??


in reply to Date::Manip and date

First, a single array element should be written like this:

$begindate_fields[2];

and not like this:

@begindate_fields[2];

The latter is an array slice. The warnings pragma would have told you this. You should always start your script with:

use strict; use warnings;

This will save you a lot of time and trouble in the long run.

Second, Date::Manip::ParseDate interprets your dates as MM/DD/YYYY, not DD/MM/YYYY. So 1988-12-13 becomes the twelfth day of the thirteenth month of 1988 — which does not exist. You need to swap the first and second array indices:

my $normalized_begindate = $begindate_fields[1] . "/" . # Month $begindate_fields[2] . "/" . # Day $begindate_fields[0]; # Year my $normalized_enddate = $enddate_fields [1] . "/" . # Month $enddate_fields [2] . "/" . # Day $enddate_fields [0]; # Year

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Date::Manip and date
by SBECK (Chaplain) on Jul 09, 2015 at 17:45 UTC
    By default ParseDate uses MM/DD/YYYY, but you can change that. If you add the following:
    Date_Init("DateFormat=non-US");
    it will interpret this as DD/MM/YYYY.
    Of course, Date::Manip will also interpret YYYY-MM-DD directly, so there's really no need to transform the dates into DD/MM/YYYY format.
Re^2: Date::Manip and date
by Anonymous Monk on Jul 09, 2015 at 10:41 UTC

    Thank you Athanasius it works like an charm

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-24 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found