dbTalk Databases Forums  

access2010 calculated table field for 'age'

comp.databases.ms-access comp.databases.ms-access


Discuss access2010 calculated table field for 'age' in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Roger
 
Posts: n/a

Default access2010 calculated table field for 'age' - 08-19-2011 , 06:33 AM






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 ?

Reply With Quote
  #2  
Old   
Phil
 
Posts: n/a

Default Re: access2010 calculated table field for 'age' - 08-19-2011 , 07:16 AM






On 19/08/2011 12:33:41, Roger wrote:
Quote:
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

Reply With Quote
  #3  
Old   
Roger
 
Posts: n/a

Default Re: access2010 calculated table field for 'age' - 08-19-2011 , 07:46 AM



On Aug 19, 6:16*am, "Phil" <p... (AT) stantonfamily (DOT) co.uk> wrote:
Quote:
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

Reply With Quote
  #4  
Old   
Phil
 
Posts: n/a

Default Re: access2010 calculated table field for 'age' - 08-19-2011 , 08:27 AM



On 19/08/2011 13:46:33, Roger wrote:
Quote:
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

Bad policy to have calculated fields in a table. Why do you want it?
Tables are for storing data, very, very rarely should they be visible to the
user. The user interface is a form (or report).

Phil

Reply With Quote
  #5  
Old   
James A. Fortune
 
Posts: n/a

Default Re: access2010 calculated table field for 'age' - 08-19-2011 , 01:12 PM



On Aug 19, 8:16*am, "Phil" <p... (AT) stantonfamily (DOT) co.uk> wrote:
Quote:
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

Reply With Quote
  #6  
Old   
Phil
 
Posts: n/a

Default Re: access2010 calculated table field for 'age' - 08-19-2011 , 05:46 PM



On 19/08/2011 19:12:51, "James A. Fortune" wrote:
Quote:
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

Whoops, James, spoy on

Try

AgeateDiff("yyyy",[Birthdate],Now())+Int(Format(Now(),"mmdd")<Format([Birthdate],"mmdd"))

Anyway my main point was not using a calculated field in a table. Unless you
are very careful and say the birthday is entered as 1 Aug 2000 so the age is
11, and then you realise that is the wrong date and enter 1 Aug 2001, unless
you are using table triggers, as I understand it, what will induce the system
to recalculate the age as 10? Phil

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.