Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Date Range Parsing

by boo_radley (Parson)
on Feb 15, 2001 at 21:23 UTC ( [id://58656]=note: print w/replies, xml ) Need Help??


in reply to Date Range Parsing

Of course it returns 100 days; your while loop simply increments through the $date counter -- there's never any logic to treat $date like a date.

I would suggest using Date::Calc to verify that $date is really a valid date, and I'm sure there's TIMTOWTDI.

here's a sample I whomped up off the top of my head:

while ($date <=$end_date) { . . . (manipulate data here) . . . ($this_year, $this_month, $this_day) = ($date =~/(\d{4})(\d(2})(\d{2}) +/) if (!checkdate ($this_year, $this_month, $this_day) { # a new month dawns $this_day=1; if ($this_month ==12) {#did december just pass $this_year++; $this_month=0; } $this_month++; #add one to the month. $date = $this_year . $this_month . $this_day; } }
Note that there's a lot of improvement to be wrung from this -- the regexp to split the date and the concatenation to reform it could be removed by using just $this_year and  $this_month and $this_day, but this might require some other adjustments to your code. update : There's a function in Date::Calc called Add_Delta_YMD which does pretty much the same thing.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found