473,432 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,432 software developers and data experts.

Access Module(modify) to account for Holidays

1
I found this module : See below to calculate elapsedtime ... I am just learning this. If any anyone could assit on how i could modfiy to calculate time elapsed not including a holiday(s) for e.g 09/03/07.
Your help would highly appreciated
ublic Function WorkdayTime(BeginTime As Date, EndTime As Date) As Single
' This function will return the elapsed time (in minutes) between the
' BeginTime and EndTime date values. It filters out time outside of
' business hours (8:00 am to 5:00 pm, Monday through Friday).
'
' Basically, go through each day in the elapsed time and subtract fourteen
' hours (900 min.) if the day is a weekday, or 24 hours (1440 min.) if the
' day is on the weekend.
Dim NewEnd As Date ' Temporary variable for the End Time
Dim ET As Double ' Elapsed time (in minutes)
Dim DOW As Integer ' Day of the Week


' Change these constants according to your own business hours
Const WEEKDAYOFFHRS = 840 ' 15 hrs. * 60 minutes
Const WEEKENDOFFHRS = 1440 ' 24 hrs. * 60 minutes
Const FIRSTWORKDAY = vbMonday ' 1st day of the work week
Const WORKDAYS = 5 ' No. of days in a work week


' First, calculate initial elapsed time (in minutes)
ET = DateDiff("n", BeginTime, EndTime)


' Set the temporary Newend to EndTime
NewEnd = EndTime


' Loop while the end time is not on the same day as the begin time
Do While DateDiff("d", BeginTime, NewEnd) > 0
' Get the day of the week for the new end time
DOW = WeekDay(NewEnd, FIRSTWORKDAY)


' If the DOW is Sat. or Sun., subtract 1440 minutes from the elapsed Time
' Otherwise, subtract 900 minutes.
If DOW > WORKDAYS Then ET = ET - WEEKENDOFFHRS Else ET = ET - WEEKDAYOFFHRS


' Subtract a day from the new end time
NewEnd = DateAdd("d", -1, NewEnd)
Loop


' This routine doesn't work correctly if BeginDate is on a
' non-work day. It'll end up with a negative number, so
' if ET < 0 then just return the actual elapsed time.
If ET < 0 Then
WorkdayTime = DateDiff("n", BeginTime, EndTime)
Else
WorkdayTime = ET
End If
End Function
Sep 5 '07 #1
1 1755
JConsulting
603 Expert 512MB
I found this module : See below to calculate elapsedtime ... I am just learning this. If any anyone could assit on how i could modfiy to calculate time elapsed not including a holiday(s) for e.g 09/03/07.
Your help would highly appreciated
ublic Function WorkdayTime(BeginTime As Date, EndTime As Date) As Single
' This function will return the elapsed time (in minutes) between the
' BeginTime and EndTime date values. It filters out time outside of
' business hours (8:00 am to 5:00 pm, Monday through Friday).
'
' Basically, go through each day in the elapsed time and subtract fourteen
' hours (900 min.) if the day is a weekday, or 24 hours (1440 min.) if the
' day is on the weekend.
Dim NewEnd As Date ' Temporary variable for the End Time
Dim ET As Double ' Elapsed time (in minutes)
Dim DOW As Integer ' Day of the Week


' Change these constants according to your own business hours
Const WEEKDAYOFFHRS = 840 ' 15 hrs. * 60 minutes
Const WEEKENDOFFHRS = 1440 ' 24 hrs. * 60 minutes
Const FIRSTWORKDAY = vbMonday ' 1st day of the work week
Const WORKDAYS = 5 ' No. of days in a work week


' First, calculate initial elapsed time (in minutes)
ET = DateDiff("n", BeginTime, EndTime)


' Set the temporary Newend to EndTime
NewEnd = EndTime


' Loop while the end time is not on the same day as the begin time
Do While DateDiff("d", BeginTime, NewEnd) > 0
' Get the day of the week for the new end time
DOW = WeekDay(NewEnd, FIRSTWORKDAY)


' If the DOW is Sat. or Sun., subtract 1440 minutes from the elapsed Time
' Otherwise, subtract 900 minutes.
If DOW > WORKDAYS Then ET = ET - WEEKENDOFFHRS Else ET = ET - WEEKDAYOFFHRS


' Subtract a day from the new end time
NewEnd = DateAdd("d", -1, NewEnd)
Loop


' This routine doesn't work correctly if BeginDate is on a
' non-work day. It'll end up with a negative number, so
' if ET < 0 then just return the actual elapsed time.
If ET < 0 Then
WorkdayTime = DateDiff("n", BeginTime, EndTime)
Else
WorkdayTime = ET
End If
End Function
Most of us build a Holiday Table to hold all the year's holidays...these tend to be different from organization to organization...but basically you need a date field formatted the way you do your dates in your DB. And then when you run this routine, you do a DLookup with the Date that's being evaluated in your loop, and if it's found in your Holiday table, you don't count it. Fairly simple to do really.
J
Sep 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rene' Nielsen | last post by:
Context: Running Windows 2003 Server on an intranet. A web is configured with an anonymous access account that is a domain account that has been granted the desired access to a file on another...
2
by: Federica T | last post by:
Another question about SQL Server tables and access grants. I've created an user 'user1' as Access account, ad also as db_owner of a selected database. Then, I've created a table as user1.table1....
12
by: Manolis | last post by:
Hi, I was wondering if there is any way to make two objects of the same class to be able to access each other's private data, like this: class A { public: void access( const A& a )...
1
by: Lee Rouse | last post by:
I have a secured Access 2000 database. There are approximately 30 user accounts already set up. Each user logs into their copy of the front-end by via a desktop shortcut which includes their...
5
by: Chand | last post by:
Private Sub tbDate_AfterUpdate() Dim cnn As New ADODB.Connection Dim rst As New ADODB.Recordset rst.CursorLocation = adUseClient Set cnn = CurrentProject.Connection rst.Open "SELECT * FROM...
2
by: darrel | last post by:
This is maybe a blue-sky wish, but I have to ask... Can .net access/modify the contents of an HTML tag on the page? For instance, in XML, one can grab and set the properties for a tag. In...
1
by: yurps | last post by:
Hello on my windowsXP coding machine I have a webapp with Anonymous Access enabled and a windows user account and password typed in...and the Integrated Window authentication checkbox tick in...
3
by: martin | last post by:
Hi, I have a website that runs under Annotmous access. I am trying to find out the account that the page is running under the line Response.Write("<hr>" & Page.User.Identity.Name & "<hr>") ...
0
by: GregInHouston2 | last post by:
I am attempting to access the files on a share on a server in my network so I can list the files there on an intranet web page. At this point, the share permissions and the NTFS permissions are...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.