Hello, Price,
It appears that DateDiff returns only the number of complete time
intervals elapsed. In effect it is truncating the difference to the
next smaller integer, rather than rounding it as you might expect. So
for example, the difference is still zero (full) days even if the
Transmission date is #2/5/2006 4:49:01 PM#. But add just one more
second, and the difference will become one (full) day.
Note that this behaviour of DateDiff is not consistent. (And this is
mentioned/implied in the documentation.) In the case of
DateInterval.Ye ar, the non-year portion of the date is disregarded, so
that (for example):
DateDiff(DateIn terval.Year, _
#12/31/2005 11:59:59 PM#, _
#1/1/2006 12:00:01 AM#)
returns a value of 1! DateInterval.Mo nth appears to work the same way
as DateInterval.Ye ar. (You've gotta love the programmer that thought
implementing DateDiff with this inconsistency would be a good idea. I
guess that he got overwhelmed with the concepts involved in
DateInterval.We ekday and DateInterval.We ekOfYear. :( )
Cheers,
Randy
Price Brattin wrote:
Why is the DateDiff function in the following code returning zero?
Dim FileDate, TransmissionDat e as Date
Dim TranDay, FileDay, DayDiff as Inteter
TransmissionDat e = #2/5/2006 1:57:56 PM#
FileDate = #2/4/2006 4:49:02 PM#
TranDay = DatePart(DateIn terval.DayOfYea r, TransmissionDat e) 'Returns 36
FileDay = DatePart(DateIn terval.DayOfYea r, FileDate) 'Returns 35
DayDiff = DateDiff(DateIn terval.DayOfYea r, FileDate, TransmissionDat e)
'Returns 0