Ask Experts Questions for FREE Help !
Ask
    smile4life's Avatar
    smile4life Posts: 1, Reputation: 1
    New Member
     
    #1

    Jul 31, 2003, 06:44 AM
    Access Date Functions
    I need to count the number of workdays between a range of dates. I know how to simply count the number of days, but can't seem to figure out how I would exclude non-workdays. Any ideas?

    Thanks.
    tadds's Avatar
    tadds Posts: 10, Reputation: 1
    New Member
     
    #2

    Nov 26, 2003, 08:17 AM
    Access Date Functions
    Hi

    I've just did a quick hack for you. Here's the code that
    you can use. Did a quick test in Excel VBA. Should work
    in any VBA (Access, Excel, etc.)
    Code:
    Function GetDayType(dd As Date) As Byte
    
    '--- This function computes day type based on given 
    Date (dd)
    ' Return Codes:
    ' 1 - Weekday (Monday to Friday)
    ' 2 - Saturday
    ' 3 - Sunday
    
    If Weekday(dd, 2) >= 1 And Weekday(dd, 2) <= 5 Then
    GetDayType = 1
    ElseIf Weekday(dd, 2) = 6 Then
    GetDayType = 2
    ElseIf Weekday(dd, 2) = 7 Then
    GetDayType = 3
    End If
    End Function
    
    Sub Simulate_Get_Weekdays()
    Dim StartDate As Date
    Dim EndDate As Date
    Dim j As Integer '-- day difference
    Dim i As Integer '-- for loop index
    Dim k As Integer '-- counter for weekdays
    
    StartDate = #11/1/2003#
    EndDate = #11/15/2003#
    
    j = DateDiff("d", StartDate, EndDate)
    k = 0
    
    For i = 1 To j
    
    '--- Tip: If you use different return code, you 
    can count weekends too!
    If (GetDayType(DateSerial(Year(StartDate), Month
    (StartDate), Day(StartDate) + i)) = 1) Then
    k = k + 1
    End If
    Next i
    
    MsgBox k '-- number of weekdays
    End Sub
    Enjoy!

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

To-date total based on current date [ 1 Answers ]

:confused: I am trying to create a forumula that will give a cumulative or "to-date" total that will exclude future months from the total. i.e. ithe point in time is August and I need to show a to-date number Through August only even though September and October are included in The...

Polynomial Functions [ 1 Answers ]

Using transformations and the zeros of the polynomial function f(x)=x(x-4)(x+2) how could you determine the zeros of y=f(2x)?? Thanks

Functions [ 7 Answers ]

Why would f(x) =pi/4x^3-sqrt2x+4 be classified as a polynomial? How would you determine the domain and range of y=x^4-4x^2? Assuming that the zeros of the function y=x^3+mx^2+nx+2 are integers how would you determine the values of m and n?? Thank you.

PHP ftp functions [ 1 Answers ]

I am trying to write a page to ftp files from my PC to my website. I am able to connect and log in using ftp_connect() and ftp_login(), but the ftp_put function won't work. What do I use as the values for the parameters? $upload= ftp_put($conn_id,$destination_file,$source_file,FTP_ASCII); if...

F-1 to H-1, what's the start date of H-1? Should be approval date or visa issue day? [ 3 Answers ]

As I mention before, I changed from F-1 to H-1 last year. I got my H-1 status in Feb 2004, but I went to my home country to get the H-1 visa stamp in August 2004. So I would like to know for counting my H-1 status, is it the date that USCIS (the Immigration) approved (which is Feb 1st), or the...


View more questions Search