×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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

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

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close