[AccessD] Subtract Date/Time Fields

Drew Wutka DWUTKA at Marlow.com
Tue Dec 16 21:24:01 CST 2008


Just subtract them.  Dates are technically double floating point
numbers.  The whole number is the number of days since Dec 30th 1899 (or
something like that).  The decimal is the fraction of the day.

So, to determine the number of days, take the result and use Fix to get
the number of days (as a date, the result would show up as a date, like
Feb. 22nd).  Then use the Hours, Minutes and Seconds function to get the
rest.  

So, here's an example:

Function GetDateDifference(dtStart As Date, dtEnd As Date) As String
Dim dtResult As Date
Dim intTemp As Long
dtResult = dtEnd - dtStart
intTemp = Fix(dtResult)
GetDateDifference = intTemp & " Days " & Hour(dtResult) & " Hours " & _ 
Minute(dtResult) & " Minutes " & Second(dtResult) & " Seconds"
End Function

Drew
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of ACTEBS
Sent: Tuesday, December 16, 2008 7:38 PM
To: access group
Subject: [AccessD] Subtract Date/Time Fields

Hi Everyone,
 
This is driving me to drink!!
 
How do you subtract 2 date/time values? eg. 17/12/2008 12:00:00   from
20/02/2009 19:40:00
 
All I am after is how many days, hours, minutes and seconds there are
between the 2 dates.
 
Anyone had any experience with this type of problem?
 
Thanks in advance...
 
Vlad


-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
The information contained in this transmission is intended only for the person or entity to which it is addressed and may contain II-VI Proprietary and/or II-VI Business Sensitive material. If you are not the intended recipient, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. You are notified that any review, retransmission, copying, disclosure, dissemination, or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited.





More information about the AccessD mailing list