The use of date


What is the time interval between the first and second dates , how can I do it



DateDiff returns the number of days between two dates. It does not return the time between two dates with times. At least that is what I found. For example, I needed to determine if 12 hours had passed since the last time it was checked. Using DateDiff returned hours in increments of 24 (ie. 24, 48, 72, etc). I had to parse out the data/times from the two variables to determine if 12 hours had passed. Not fun. Be nice if there was another way to determine the time interval between two date/time variables.



Can you show the actual code you are using? To return the number of hours you should do this:

retVal = DateDiff(“h”, date1, date2)

“h” tells the function to return the result in the “exact” number of hours (not sure if it will round up or down for partial hours).


My code for determining a 12 hour elapsed time may not be what you need. If you want that I’ll put it in another post. When I have the time I’ll make a true time/date interval routine and post that as well. In the mean time the following lines of code might get you started. They are what is needed to do this:

DateTimeBegin = “9/06/2017 8:09:56 PM” 'test data
DateTimeEnd = “9/06/2017 10:02:56 PM” 'test data
daysDiff = CInt(DateDiff(“d”,DateTimeBegin,DateTimeEnd))
m1 = (CInt(Hour(DateTimeBegin)) * 60) + CInt(Minute(DateTimeBegin))
m2 = (CInt(Hour(DateTimeEnd)) * 60) + CInt(Minute(DateTimeEnd))



Thank you for your reply, the idea of what I want to do it its , the first date is defined and the another
Then Calculates the difference in days


If all you need is the number of days use DateDif:

daysDiff = CInt(DateDiff(“d”,DateTimeBegin,DateTimeEnd))