PC Review


Reply
Thread Tools Rate Thread

How to calculate 6 working days between two dates

 
 
Nilay Excel 2003
Guest
Posts: n/a
 
      1st Dec 2007
I have two dates from 9 Nov 2007 to 3 Dec 2007.
I want to calculate workdays for this mentained range & getting result as 17
Days
by putting the formula as networkdays. Problem is that I want to consider 6
working days instead of 5 working days. How to get results??
 
Reply With Quote
 
 
 
 
Greg Wilson
Guest
Posts: n/a
 
      1st Dec 2007
Try:

Sub Test()
MsgBox GetWorkdays("9 Nov 2007", "3 Dec 2007")
End Sub

Function GetWorkdays(FirstDate As Date, LastDate As Date) As Integer
Dim i As Integer, ii As Integer
ii = 0
For i = 0 To (LastDate - FirstDate)
If Weekday(FirstDate + i) <> 1 Then ii = ii + 1
Next
GetWorkdays = ii
End Function

Regards,
Greg
 
Reply With Quote
 
Nilay Excel 2003
Guest
Posts: n/a
 
      1st Dec 2007
Thanks, it works...

But the details I actualy need to fill in Excel worksheet is as follows:

Start Date: 9 Nov 2007
End Date : 3 Dec 2007
1) Sundays on : dd-mm-yy , dd-mm-yy,........
2) Holidays on : ........
3) Total Working days : ?? (by considering Monday to saturday as working Days)
I am to too exposed to programing, so please provide me the simplest
way to get the results that I need.
Thanks in advance for your help.

*Nilay*





"Greg Wilson" wrote:

> Try:
>
> Sub Test()
> MsgBox GetWorkdays("9 Nov 2007", "3 Dec 2007")
> End Sub
>
> Function GetWorkdays(FirstDate As Date, LastDate As Date) As Integer
> Dim i As Integer, ii As Integer
> ii = 0
> For i = 0 To (LastDate - FirstDate)
> If Weekday(FirstDate + i) <> 1 Then ii = ii + 1
> Next
> GetWorkdays = ii
> End Function
>
> Regards,
> Greg

 
Reply With Quote
 
Greg Wilson
Guest
Posts: n/a
 
      1st Dec 2007
You might also try in the worksheet function ng for another option.

Function example:-
1. Put the 1st date in cell A1
2. Put the last date in cell A2
3. Put in cells A3 to A12 the holidays
4. Enter this in cell C1:
=GetWorkdays(A1, A2, A3:A12)

Function GetWorkdays(FirstDate As Date, LastDate As Date, _
Optional Hols As Variant) As Integer
Dim i As Integer, ii As Integer, wkdys As Integer
Dim dy As Date
Dim f As Boolean

wkdys = 0
For i = 0 To (LastDate - FirstDate)
dy = CDate(FirstDate + i)
If Weekday(dy) <> 1 Then
f = False
If Not IsMissing(Hols) Then
For ii = 1 To Hols.Count
If Len(Hols(ii)) = 0 Then Exit For
If CDate(Hols(ii)) = dy Then
f = True
Exit For
End If
Next
End If
If Not f Then wkdys = wkdys + 1
End If
Next
GetWorkdays = wkdys
End Function

Greg
 
Reply With Quote
 
Nilay Excel 2003
Guest
Posts: n/a
 
      5th Dec 2007
Dear Greg,
Thanks. This function is working absolutely fine.

With Regards,
Nilay


"Greg Wilson" wrote:

> You might also try in the worksheet function ng for another option.
>
> Function example:-
> 1. Put the 1st date in cell A1
> 2. Put the last date in cell A2
> 3. Put in cells A3 to A12 the holidays
> 4. Enter this in cell C1:
> =GetWorkdays(A1, A2, A3:A12)
>
> Function GetWorkdays(FirstDate As Date, LastDate As Date, _
> Optional Hols As Variant) As Integer
> Dim i As Integer, ii As Integer, wkdys As Integer
> Dim dy As Date
> Dim f As Boolean
>
> wkdys = 0
> For i = 0 To (LastDate - FirstDate)
> dy = CDate(FirstDate + i)
> If Weekday(dy) <> 1 Then
> f = False
> If Not IsMissing(Hols) Then
> For ii = 1 To Hols.Count
> If Len(Hols(ii)) = 0 Then Exit For
> If CDate(Hols(ii)) = dy Then
> f = True
> Exit For
> End If
> Next
> End If
> If Not f Then wkdys = wkdys + 1
> End If
> Next
> GetWorkdays = wkdys
> End Function
>
> Greg

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calculate working days between 2 dates KAquestions Microsoft Access Queries 6 13th Jan 2009 06:21 PM
Calculate Working Days between two dates =?Utf-8?B?c3RlcGg=?= Microsoft Access Queries 2 21st Jul 2006 07:00 PM
Calculate working days between dates? =?Utf-8?B?QmFyYg==?= Microsoft Access Form Coding 14 15th Dec 2005 11:12 PM
Calculate Working Days Between Dates =?Utf-8?B?R3JlZw==?= Microsoft Access Form Coding 14 8th Nov 2005 09:55 AM
How do I calculate working days only from between 2 dates? =?Utf-8?B?Q2FzZQ==?= Microsoft Access Queries 2 27th Oct 2005 07:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:06 PM.