Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 27th, 2006, 02:59 PM
Authorized User
 
Join Date: Jun 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default special date/time comparisons

Greetings,

I hope everyone is doing well.

I have a table setup with multiple date/time columns that I need to run date comparisons on. Initially, I was just using a simple Date1 - Date2 calculation to get the difference in days. However, my requirements have recently changed such that I must calculate elapsed business hours rather than just the plain elapsed time.

For example, let's say Monday's and Tuesday's business hours are 7am - 7pm. If an order is placed at 4pm on Monday and delivered at 8am on Tuesday, the regular elapsed time would be 16 hours. The elapsed time in business hours would be 4 hours.

Therefore, I would need an algorithm that could calculate elapsed business hours if given a schedule of business hours.

Before I go off to try to put this together, I was wondering if anyone had tackled a similar task and had some sample code to offer.

Thanks for the help.

 
Old June 27th, 2006, 04:00 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't have all the code syntax down, but an algorithm such as the following would do the trick for you:

Dim dteCOB As Date
Dim dteSOB As Date
Dim HoursPerDate = 12
Elapsed = 0
If DateValue(Date1) = DateValue(Date2) Then
  Elapsed = TimeValue(Date2) - TimeValue(Date1)
Else
' You may need to do some string manipulation on the DateValue returns below to adjust the # locations to the start & end of the date
  dteCOB = DateValue(Date1) & "7:00 PM"
  dteSOB = DateValue(Date2) & "7:00 AM"
  Elapsed = DateDiff('h', dteCOB, Date1) + DateDiff('h', Date2, dteSOB) + (DateDiff('d',Date2,Date1) - 1) * HoursPerDay
End If

Hope that helps.

 
Old July 3rd, 2006, 09:32 AM
Authorized User
 
Join Date: Jun 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply. I haven't had a chance to try it yet because I had a new "hot" task thrown at me. I am sure nobody else ever has to deal with anything like that...

 
Old July 12th, 2006, 11:41 AM
Authorized User
 
Join Date: Jun 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks again for the help on this one. I sat down yesterday to start putting this together and the sample algorithm you gave helped a lot. I am really close to having it done now.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting Time from Date/Time Navy1991_1 XSLT 2 June 3rd, 2008 12:03 PM
date and time in EST time zone anboss XSLT 1 May 21st, 2008 01:42 PM
Time Comparisons of Nodes Neal XSLT 4 February 16th, 2006 11:38 AM
storing special special characters in nvarchar... ACE2084 SQL Server 2000 2 February 9th, 2005 11:45 AM
insert system date. no date and time jimmy Access VBA 6 November 20th, 2003 01:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.