Posted on 2007-02-05 20:12:58-08 by porkisgood
DateCalc not getting YEAR difference in business mode
I just started using Date::Manip and so far it is AWESOME! I have one major question, however. In my code I'm getting the difference between two business dates, however the resulting number doesn't seem to take the year into account!

Here's what I've written:

$total_days = Delta_Format( DateCalc($first_date, $second_date, \$err, 2), 1, "%dt");

Where $first_date = 2007011000:00:00 and $second_date = 2007020200:00:00 I'm getting the correct answer of "17".

However where $first_date = 2006121400:00:00 and $second_date = 2007013100:00:00, I'm getting "12" and I should be getting 33.

(Dec 24,25,31 and Jan 1 are specified as Holidays in my .cnf file, and my work week is 1-5/M-F)

Is there something special I need to specify or do I need to format the date differently?!?!

TIA!

Direct Responses: 4247 | Write a response
Posted on 2007-02-05 20:18:33-08 by porkisgood in response to 4246
Re: DateCalc not getting YEAR difference in business mode
Wow, I feel special. Right after I posted this I figured it out. When I convert it to Delta I'm using %dt which doesn't take into account the year value. WHOOPS!
Direct Responses: 4249 | Write a response
Posted on 2007-02-05 20:55:09-08 by porkisgood in response to 4247
Re: DateCalc not getting YEAR difference in business mode
Sorry for the multiple posts.. I wish I could edit my previous post! I was using Delta_Format in "exact" mode when I needed to be using "approx".

so instead of: $total_days = Delta_Format( DateCalc($first_date, $second_date, \$err, 2), 1, "%dt");

it now reads: $total_days = Delta_Format( DateCalc($first_date, $second_date, \$err, 2), "approx",1, "%dt");

and returns a value of 43.438.

The only problem is Dec of 2006 only had 19 business days.. not 31...
Direct Responses: 4251 | Write a response
Posted on 2007-02-05 21:28:07-08 by porkisgood in response to 4249
Re: DateCalc not getting YEAR difference in business mode
Set the DateCalc mode to 3! That sets the "Delta" to something that is business day compliant.

$total_days = Delta_Format( DateCalc($first_date, $second_date, \$err, 3), "approx",1, "%dt");

This will accurately return the number of business days (3 decimal places) between the two dates. Yay!

Again, sorry for the multiple posts.
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.