[AccessD] Tip concerning dates in Access

Heenan, Lambert Lambert.Heenan at AIG.com
Mon Oct 23 11:05:44 CDT 2006


Often you'll have a date field in a table that has the date and time stored
in it, but you may want to run a query that simply shows the date, without
the time.
 
Up to now I have been using Clng() to strip off the time part in a query
like this:
 
A Date: Cdate(Clng(dSomeDate))
 
but I just realized the lurking bug in this. CLng rounds up or down,
depending on which side of noon the time part is. So 1/1/2006 08:30:00 AM
would display as 1/1/2006, but 1/1/2006 12:30:00 PM would be 1/2/2006.
 
To avoid this problem use Fix() instead of Clng()...
 
A Date: Cdate(Fix(dSomeDate))
 
Fix always returns just the 'integer' part of the number passed to it. The
documentation suggests that Fix only returns an integer, but in fact it is
capable or returning Longs too, which is what date values are equivalent to.
 
HTH
 
Lambert


More information about the AccessD mailing list