×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*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.

# Number of working days between two date fields

 Forum Search FAQs Links MVPs

## Number of working days between two date fields

(OP)
Hi Dnoeth (Instructor),

Had refer your code to calculate working days, want to include holidays in the same how do i do that?

select
/** The number of whole weeks * 5 **/
((enddate - startdate + 1) / 7) * 5 +

/** the number of remaining days, that don't fall on Saturday or Sunday **/
(case when (enddate - startdate + 1) mod 7 < 1
or (((startdate - DATE '0001-01-01') mod 7) + 1) in (6,7)
then 0 else 1 end) +
(case when (enddate - startdate + 1) mod 7 < 2
or (((startdate + 1 - DATE '0001-01-01') mod 7) + 1) in (6,7)
then 0 else 1 end) +
(case when (enddate - startdate + 1) mod 7 < 3
or (((startdate + 2 - DATE '0001-01-01') mod 7) + 1) in (6,7)
then 0 else 1 end) +
(case when (enddate - startdate + 1) mod 7 < 4
or (((startdate + 3 - DATE '0001-01-01') mod 7) + 1) in (6,7)
then 0 else 1 end) +
(case when (enddate - startdate + 1) mod 7 < 5
or (((startdate + 4 - DATE '0001-01-01') mod 7) + 1) in (6,7)
then 0 else 1 end) +
(case when (enddate - startdate + 1) mod 7 < 6
or (((startdate + 5 - DATE '0001-01-01') mod 7) + 1) in (6,7)
then 0 else 1 end) as workingdays
from
(
select
date '2003-01-06' as startdate,
date '2003-01-17' as enddate
) dt

Preshit

### RE: Number of working days between two date fields

Working days? Are there never any Holidays? No one ever works on Saturday or Sunday? If so, you really just want to count MTWTF days and not Sat/Sun. a.k.a. weekdays.

==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity

#### 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.

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

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!