[AccessD] Date Diff Help It cant be this hard

Stuart McLachlan stuart at lexacorp.com.pg
Sun Jan 8 23:09:36 CST 2006


On 8 Jan 2006 at 20:39, Joe Hecht wrote:

> 
>     datenow = Now()
>     dateborn = Me.DOB
> Me.txtage = DateDiff("yyyy", datenow, dateborn)
> 

This will not always give the correct age since it only works on the year 
part and doesn't take into account the actual dates. It will be one year 
too high if datenow is earlier in the year than dateborn.

ie DateDiff("yyyy","31 Dec 05","1 Jan 06") will return 1 even though it is 
only one day difference (to say nothing of your version always returning a 
negative value because the arguments are the wrong way round)

Try
Me.txtage = Datediff("yyyy",dateborn,datenow) + _
(DatePart("y", datenow) < DatePart("y",dateborn))






-- 
Stuart





More information about the AccessD mailing list