1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Access DateDiff

Discussion in 'Business Applications' started by computerman29642, Oct 10, 2008.

Thread Status:
Not open for further replies.
  1. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    I have setup a query to use the DateDiff function.

    Code:
    Expr1: DateDiff("d",date1,date2)
    
    As you can see, I am using the Days interval. Is there a way to limit that to only work days (M-F)?
     
  2. Ziggy1

    Ziggy1

    Joined:
    Jun 17, 2002
    Messages:
    2,551
    Check this out... http://www.techonthenet.com/access/modules/workdays.php


    Here is the text for anyone else...links sometimes change over time ( for anyone looking at this in the future).

    Access: Calculate the number of workdays between two dates in Access 2003/XP/2000/97

    Question: In Access 2003/XP/2000/97, I need to calculate the number of workdays between two dates (ie: elapsed days excluding Saturdays and Sundays).

    For example, if I have 3/4/2005 and 3/29/2005, the number of workdays is 17. How can I calculate this?

    Answer: You can calculate the number of workdays between two dates using our function below:

    Open your Access database, click on the Modules tab and create a new Module. Paste in the following code:

    Function CalcWorkdays(StartDate, EndDate) As Integer

    Dim LTotalDays As Integer
    Dim LSaturdays As Integer
    Dim LSundays As Integer

    On Error GoTo Err_Execute

    CalcWorkdays = 0

    If IsDate(StartDate) And IsDate(EndDate) Then
    If EndDate <= StartDate Then
    CalcWorkdays = 0
    Else
    LTotalDays = DateDiff("d", StartDate - 1, EndDate)
    LSaturdays = DateDiff("ww", StartDate - 1, EndDate, 7)
    LSundays = DateDiff("ww", StartDate - 1, EndDate, 1)

    'Workdays is the elapsed days excluding Saturdays and Sundays
    CalcWorkdays = LTotalDays - LSaturdays - LSundays

    End If
    End If

    Exit Function

    Err_Execute:
    'If error occurs, return 0
    CalcWorkdays = 0

    End Function
     

    Attached Files:

  3. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    Thanks Ziggy. I wiil take a look at th elink provided.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/757944

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice