![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I've got a table with a field for 'birthdate' I want to create a calculated field for 'age' this expression works IIf(IsNull([birthDate]),Null,Year(DateSerial(2011,8,20))- Year([birthDate])) but how do I replace "DateSerial(2011,8,20)" with the current date ? date() and now() don't seem to be valid functions ? can this be done with a calculated table field ? |
#3
| |||
| |||
|
|
On 19/08/2011 12:33:41, Roger wrote: I've got a table with a field for 'birthdate' I want to create a calculated field for 'age' this expression works IIf(IsNull([birthDate]),Null,Year(DateSerial(2011,8,20))- Year([birthDate])) but how do I replace "DateSerial(2011,8,20)" with the current date ? date() and now() don't seem to be valid functions ? can this be done with a calculated table field ? Age: IIf(Not IsNull([BirthDate]),DateDiff("yyyy",[Birthdate],Date())) Age in years Phil |
#4
| |||
| |||
|
|
On Aug 19, 6:16*am, "Phil" <p... (AT) stantonfamily (DOT) co.uk> wrote: On 19/08/2011 12:33:41, Roger wrote: I've got a table with a field for 'birthdate' I want to create a calculated field for 'age' this expression works IIf(IsNull([birthDate]),Null,Year(DateSerial(2011,8,20))- Year([birthDate])) but how do I replace "DateSerial(2011,8,20)" with the current date ? date() and now() don't seem to be valid functions ? can this be done with a calculated table field ? Age: IIf(Not IsNull([BirthDate]),DateDiff("yyyy",[Birthdate],Date())) Age in years Phil I think this works in a query, but not a table calculated field when I try it as a calculated field, I get the expression... cannot be used as a calculated column |
#5
| |||
| |||
|
|
On 19/08/2011 12:33:41, Roger wrote: I've got a table with a field for 'birthdate' I want to create a calculated field for 'age' this expression works IIf(IsNull([birthDate]),Null,Year(DateSerial(2011,8,20))- Year([birthDate])) but how do I replace "DateSerial(2011,8,20)" with the current date ? date() and now() don't seem to be valid functions ? can this be done with a calculated table field ? Age: IIf(Not IsNull([BirthDate]),DateDiff("yyyy",[Birthdate],Date())) Age in years Phil |
#6
| |||
| |||
|
|
On Aug 19, 8:16*am, "Phil" <p... (AT) stantonfamily (DOT) co.uk> wrote: On 19/08/2011 12:33:41, Roger wrote: I've got a table with a field for 'birthdate' I want to create a calculated field for 'age' this expression works IIf(IsNull([birthDate]),Null,Year(DateSerial(2011,8,20))- Year([birthDate])) but how do I replace "DateSerial(2011,8,20)" with the current date ? date() and now() don't seem to be valid functions ? can this be done with a calculated table field ? Age: IIf(Not IsNull([BirthDate]),DateDiff("yyyy",[Birthdate],Date())) Age in years Phil Some further testing will show that your expression does not produce conventional age values when the birthdate is after the current date in the year. That problem has been solved in more than one way in this NG. James A. Fortune CDMAPoster (AT) FortuneJames (DOT) com |
ateDiff("yyyy",[Birthdate],Now())+Int(Format(Now(),"mmdd")<Format([Birthdate],"mmdd"))![]() |
| Thread Tools | |
| Display Modes | |
| |