Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare 2 dates and get number of business days between the 2 dates

Status
Not open for further replies.

ljsmith91

Programmer
May 28, 2003
305
0
0
US
I need some expertise. I have 2 dates pulled out of a database record. They are in scalars $date_start and $date_end. I convert the dates to epoch and get the number of days between the 2 dates and place this value in another scalar called $day_diff_in_days. So, $date_fiff_in_days can be equal to "0" or "1" or "2" or "5" or "11" etc.

I now have to determine whether $date_diff_in_days is less or equal to an agreed service of "2" business days or less.

How would I do this ? Can anyone help me or direct me towards a way of accomplishing this by factoring in 2 weekend days each week? Is there a way of also factoring in US holidays? Thanks for any advice or assistance that you could offer. -ljs
 
I use this code
Code:
###########################
# Date Difference in Days #
###########################
sub dateDiff {
    
    # accepts IS dates (yyyy-mm-dd) - most recent date first!
    my ($date1,$date2) = @_;
    
    use Date::Calc qw(Delta_Days);

    # create dates array
    my @date1 = split(/-/,$date1));
    my @date2  = split(/-/,$date2);  

    # return days difference
    return Delta_Days(@date2,@date1);    
}

but basically have a look at the module Date::Calc and the methods available for messing around with dates.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top