473,471 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Current Age from birthday field

5 New Member
I need a box on my form that computes a person's age using their birthday field entered on the same form (and stored in the table). The current age doesn't need to be stored in a table. I just want it to be visible so that I don't have to do the figuring in my head. Suggestions on the expression that would be needed to show the current age?

I am using Access 2003 with Windows XP in English.

Thanks, Tim
Oct 27 '06 #1
10 8360
smitchcoff
3 New Member
Hey, take a look at the datediff function. If you search the help file, something should come up... Maybe something like:

lbl_age = datediff('yyyy', cboBirthDate, date)

for more info/syntax, check out:
http://www.techonthenet.com/access/functions/date/datediff.php

Hope this helps!

I need a box on my form that computes a person's age using their birthday field entered on the same form (and stored in the table). The current age doesn't need to be stored in a table. I just want it to be visible so that I don't have to do the figuring in my head. Suggestions on the expression that would be needed to show the current age?

I am using Access 2003 with Windows XP in English.

Thanks, Tim
Oct 27 '06 #2
PEB
1,418 Recognized Expert Top Contributor
And also I can say that it's better to check the Access forum this post is largely discussed

:)
Oct 27 '06 #3
radio1
14 New Member
The following works for me (in Access 2002) -- my Date-Of-Birth field is called "dob". This formula prevents "error" strings from appearing in the calculated age field when the dob field hasn't yet been entered or is invalid.

Expand|Select|Wrap|Line Numbers
  1. =IIf(Nz([dob],"")="","",DateDiff("yyyy",[dob],Now())+(Now()<DateSerial(Year(Now()),Month([dob]),Day([dob]))))
  2.  
Hope this helps,

radio1
Oct 27 '06 #4
timgeitz
5 New Member
Radio, thanks for the coding, it worked fine just the way you had it with my fireld change.

Blessings,
timgeitz
Oct 28 '06 #5
radio1
14 New Member
You're welcome.

Please note that there are possibly "bigger/better/stronger/faster" ways of doing it -- I'm still quite new at Access and VBA coding. You just happened to ask the one question in the entire forum that I was apparently qualified to answer!

Cheers,

-radio1
Oct 28 '06 #6
NeoPa
32,556 Recognized Expert Moderator MVP
That's how it works for all of us radio1.
(Excluding MMcCarthy of course who's just a posting machine of all known Access issues - My hat is permanently off ;-) )
Just reply to the ones that we can help on, which is what you did - so ups to you on that.
Oct 28 '06 #7
PEB
1,418 Recognized Expert Top Contributor
Hi,

First the function

IIf(Nz(#23/03/2000#,"")="","","") a test like this gives me an error:
wrong number of arguments for the function nz()

Nz() is used like : nz(#23/03/2000#) or nz("23/03/2000") only with one argument...

But this part of the function isn't important coz it verifies if there is a birthdate introduced... So keep a part...

The rest of the function is:

DateDiff("yyyy","23/03/2000",Now())+(DateSerial(Year(Now()),Month("23/03/2000"),Day("23/03/2000")))

With string values it doesn't give me correct results...

with date values:

the same result...

But the function DateDiff("yyyy","23/03/2000",Now()) gives just the age without monts and days...

But after some verification you can use this one:

=str(Datediff("yyyy",Cvdate(Format("23/03/2000","DD/mm/yyyy")),Now()))+"/"str(Datediff("m",Dateserial(Year(Now()),Month(Cvd ate(Format("23/03/2000","DD/mm/yyyy"))),Day(Cvdate(Format("23/03/2000","DD/mm/yyyy")))),Now()))+"/" +str(Datediff("d",Dateserial(Year(Now()),Month(Now ()),Day(Cvdate(Format("23/03/2000","DD/mm/yyyy")))),Now()))

Have a nice evening!

The following works for me (in Access 2002) -- my Date-Of-Birth field is called "dob". This formula prevents "error" strings from appearing in the calculated age field when the dob field hasn't yet been entered or is invalid.

Expand|Select|Wrap|Line Numbers
  1. =IIf(Nz([dob],"")="","",DateDiff("yyyy",[dob],Now())+(Now()<DateSerial(Year(Now()),Month([dob]),Day([dob]))))
  2.  
Hope this helps,

radio1
Oct 28 '06 #8
PEB
1,418 Recognized Expert Top Contributor
radio 1 10x for the idea...

it was a very good way to find a short way to calculate it..

Before there was threads there , where we with mcarthy have created a long calculation functions about this...

And I wasn't able to begin a thread like the previous one....

But it was a very good idea...

:)
Oct 28 '06 #9
NeoPa
32,556 Recognized Expert Moderator MVP
The optional second parameter to the Nz() function specifies the value to return if the first parameter evaluates to Null.

Thus
Expand|Select|Wrap|Line Numbers
  1. Nz([A], [b])
is equivalent to
Expand|Select|Wrap|Line Numbers
  1. IIf(IsNull([A]), [b], [A])
Oct 28 '06 #10
PEB
1,418 Recognized Expert Top Contributor
I'm afraid but It gives me error on My Access...

And don't accept this optional argument...

But in this case it isn't a problem! It's unsignifcant for the function that calculates the age :)

So discuss it in different thread???
:)

The optional second parameter to the Nz() function specifies the value to return if the first parameter evaluates to Null.

Thus
Expand|Select|Wrap|Line Numbers
  1. Nz([A], [b])
is equivalent to
Expand|Select|Wrap|Line Numbers
  1. IIf(IsNull([A]), [b], [A])
Oct 28 '06 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

51
by: Sandra | last post by:
I was given this problem for extra credit and I am just stuck ! BTW - I am not asking for source code and I am not asking anyone to do my homework as I do want to learn .. I just need a hint or two...
13
by: Luigi | last post by:
Imagine I have a small, static, personal site (I do, actually: http://kirpi.it/). And imagine that, just below the title of the page, I would like to have a comment, or a news line, or a birthday...
1
by: Ben | last post by:
Hi I am currently building a database in Access 97 and have a (quite easy) question. I want to produce a query / report that will bring out all the people in the database that have a birthday...
1
by: Claude Alain | last post by:
Hello! We are a small non-profit organisation with about 400 members. We have created a database using Access97 which contains tombstone information on our members, including home adresses and...
7
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
6
by: vijayk | last post by:
Hi all, I have a field which has data as YYYYMMDD, and I have to find the age of the person by substracting it from current date. can you please please advice... thanks
5
by: NomoreSpam4Me | last post by:
Hi, i did a search and find the way to get the birthday without the year. My field is yyyy/mm/dd, (birthday). I also have a day field (1 to 31) and a month field. (1 to 12) My problem is: I...
13
kestrel
by: kestrel | last post by:
Sheila and He-Man are twins; Sheila is the OLDER twin. Assume they were born immediately after each other, an infinitesimally small - but nonzero - amount of time apart. During one year in the...
1
by: stilldancin12 | last post by:
Ok so i have to write an application that asks for the users birthday and replies with they day of the week in which he or she is born on, using the java program. This is what I have so far.It gives...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.