Important alert: (current site time 7/15/2013 7:04:06 PM EDT)
 

article

Access 2000 Calculating Working Days

Email
Submitted on: 10/3/2002 12:30:35 PM
By: davepamn 
Level: Intermediate
User Rating: By 5 Users
Compatibility: SQL Server 2000
Views: 24878
(About the author)
 
     This article explains how to use Access 2000 date functions when determining 1) the number of work days representing an interval between two dates 2) the projected end working date calculated from a start date and number of hours worked.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				
Author David Nishimoto
davepamn@relia.net
Articles: Calculating Work days and Project Completion Dates

This article explains how to use Access 2000 date functions when determining 1) the number of work days representing an interval between two dates 2) the projected end working date calculated from a start date and number of hours worked.

The GetEndWorkDay function was used in Schedule Extreme Pro. The user enters in a start date and actual hours as parameters to the function. The GetEndWorkDay calculates the date in the future the work was completed. So, if today was 10/2/2002 and the actual hours was 12. The actual end date would be 10/3/2002.

Part two includes using the GetNumberOfWorkDays function. The problem is determine what percent of estimated time, actual time represents. Estimated work days is the time interval beto complete a task based on a start and end date. Comparing estimate to actual, I can provide the percent of work completed both under or over allocated percents.


1. DateDiff specifics a number of time intervals between two dates.
2. DateDiff (interal,date1,date2,firstdayofweek,firstweekofyear)
	interval 
		yyyy	= year
		q	= quarter
		m	= month
		y	= day of year
		d	= day
		w	= weekday
		ww	= week
		h	= hour
		n	= minute
		s	= second
	date1 and date2 are used to calculate the interval
	
	firstdayofweek is sunday unless specified
	firstweekofyear is jan 1 unless specified
3. Weekday returns a number representing the day of the week.
	return values are
		Sunday		= 1
		Monday 	= 2			
		Tuesday	= 3
		Wednesday	= 4
		Thursday	= 5
		Friday		= 6
		Saturday	= 7
4. First determine the number of day between the two dates. Calculating the number of
work days is done by not adding Saturday and Sunday dates. A query extract from a table contain
all holidays for the year can also be added for increased accuracy.

Public Function GetNumberOfWorkDays(sStartDate, sEndDate)
 Dim iDays
 Dim iWorkDays
 Dim sDay
 Dim i
 
 iDays = DateDiff("d", sStartDate, sEndDate)
 
 iWorkDays = 0
 
 For i = 0 To iDays
'First day of the week is sunday
sDay = Weekday(DateAdd("d", i, sStartDate))
If sDay <> 1 And sDay <> 7 Then
 iWorkDays = iWorkDays + 1
End If
 Next
 GetNumberOfWorkDays = iWorkDays
End Function

1. DateAdd returns a date to which a specific 
time interval has been added. In this sample the 
interval is "Day".
	List of Interval Settings:
		yyyy 	= year
		q 	= quarter
		m	= month
		y	= day of year
		d	= day
		w	= weekday
		ww	= week
		h	= hour
		n	= minute
		s	= second
2. Increment through a range of possible work days to find the end work date. The
number of work days is determined by dividing the hours by eight. This assumes
an eight hour work day. Ignore saturday and sunday as a work day. Once
the number of found work days equals the work day interval, stop and return 
the date as the final work date.

Public Function GetEndWorkDay(sStartDate, sHours)
 Dim iHoursToDays
 Dim iCount
 Dim bFlag
 Dim sEndDate
 Dim sCheckDate
 Dim iFoundCount
 Dim sDay
 
'Assume an eight hour day
iHoursToDays = round(sHours / 8,0)
sEndDate = sStartDate
If iHoursToDays > 1 Then
 bFlag = False
 iCount = 0
 iFoundCount = 0
 Do While bFlag = False
iCount = iCount + 1
sCheckDate = DateAdd("d", iCount, sStartDate)
sDay = Weekday(sCheckDate)
If sDay <> 1 And sDay <> 7 Then
 sEndDate = sCheckDate
 iFoundCount = iFoundCount + 1
End If
If iFoundCount >= iHoursToDays Then
 Exit Do
End If
 Loop
End If
GetEndWorkDay = sEndDate
End Function


Other 9 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

1/3/2005 4:53:10 AM

12345678
(If this comment was disrespectful, please report it.)

 
9/14/2005 8:00:28 AMbudi

can u translate code for indonesia language, maybe i can easy to take this, thks 4 ur support
(If this comment was disrespectful, please report it.)

 
10/24/2005 10:45:20 PMrico

working compute
(If this comment was disrespectful, please report it.)

 
11/26/2006 12:26:16 PMgiannhs

how from a textbox can i copy the text and to paste to another form in access
(If this comment was disrespectful, please report it.)

 
5/9/2007 5:25:27 AMkulbhushan

Access 2000 Calculating Working Days
(If this comment was disrespectful, please report it.)

 
12/3/2007 1:56:02 AMAll

I want current date + 5 days in SQL not by Programming, I have this issue,for example i have this date 2007/11/23
i want add 20 days
mean 2007/11/23 + 20 ?
(If this comment was disrespectful, please report it.)

 
9/16/2011 10:50:17 AMMelky

Nice.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.