Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 May 5th, 2005, 09:31 AM
Authorized User
 
Join Date: Jun 2003
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calculating hours and minutes between to dates

Hi,

I'm having some difficulty trying to get to grips with the Datediff function and working out the difference in hours between to dates/times.

Has anyone successfully tried this????

Thanks

Tim

Tim
__________________
Tim
 
Old May 5th, 2005, 02:43 PM
Registered User
 
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Tim,

what are you trying to calculate? can you give a specific example on what you want to calculate using datediff function?

i found a couple articles on date and time. hopefully these will help you.

http://support.microsoft.com/default...b;en-us;210276

http://www.mvps.org/dmcritchie/excel/datetime.htm

 
Old May 5th, 2005, 04:07 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Let’s say that you wanted to return this value into lngHoursBetween:
Code:
    Dim lngHoursBetween As Long

    lngHoursBetween = datediff("h", dtDate_1, dtDate_2)
    That’s it! Alternately:
Code:
    Dim lngHoursBetween As Long
Code:
    lngHoursBetween = datediff("h", "05/01/2005", "05/03/2005") ' Returns     48.
    lngHoursBetween = datediff("h", "05/01/2002", "05/03/2005") ' Returns 26,352.
 
Old May 5th, 2005, 05:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this:

Code:
' Code to time a process
Dim dtStartTime As Date
Dim dtEndTime As Date
Dim dDiffMinutes As Double
Dim sDiffMinutes As String

' Logic to show the running time of the process
' Put this at the beginning.

dtStartTime = Now()
Debug.Print "Started at: " & Format(dtStartTime, vbGeneralDate)
Debug.Print String(32, "=")

' Put the process to be timed here
' ====================================================================

' ====================================================================
' Put this at the end
dtEndTime = Now()
dDiffMinutes = CDbl((DateDiff("s", dtStartTime, dtEndTime)) / 60)
sDiffMinutes = CStr(dDiffMinutes)
Debug.Print String(32, "=")
Debug.Print "Started at: " & CStr(dtStartTime)
Debug.Print "Ended at:   " & CStr(dtEndTime)
Debug.Print "Run time:   " & sDiffMinutes & " minute(s)"
Debug.Print String(32, "=")

End Sub
Rand
 
Old May 10th, 2005, 07:36 AM
Authorized User
 
Join Date: Jun 2003
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for all the help guys.

Will give them a try.

Tim

Tim





Similar Threads
Thread Thread Starter Forum Replies Last Post
convert time to minutes stolte XSLT 3 November 21st, 2008 04:12 AM
how to set the maximum minutes in setTimeout() or kasipandian Javascript 2 February 18th, 2008 12:37 PM
Remoting aborts thread after 2 minutes BrainWave C# 1 August 14th, 2007 12:15 PM
Remoting timing out after 2 minutes BrainWave ASP.NET 2.0 Professional 0 August 13th, 2007 06:54 AM
Calculating number of days between multiple dates Vann Access 4 December 3rd, 2004 08:26 PM





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