DIFFERENCE from date and return age

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

DIFFERENCE from date and return age

Post by sal21 »

field DATA1 have 12-dic-78 (the field have shorth date property)
field ANNI (integer)

i need to update ANNI with difference from DATA1-current date (now), how to?

in my case the result in ANNI is 36

2014-1978=36

with a sql query, please

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DIFFERENCE from date and return age

Post by HansV »

UPDATE MyTable SET ANNI = Year(Date())-Year(DATA1)
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: DIFFERENCE from date and return age

Post by sal21 »

HansV wrote:UPDATE MyTable SET ANNI = Year(Date())-Year(DATA1)
OPS...

but if i have 12-12-29

naturally the account is born in 1929!

the query return negative number or wrong result :scratch:

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DIFFERENCE from date and return age

Post by HansV »

That depends on a Windows setting - see XL2000: Gestione degli anni a due cifre in Microsoft Excel (it applies to other applications too). By default, two-digit years 00 - 29 are interpreted as 2000 - 2029, and two-digit years 30 - 99 are interpreted as 1930 - 1999.
Best wishes,
Hans