473,320 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Age from Date of Birth

83
I would like Age to automatically be calculated in years from the date of birth. I have a date of birth variable and an age variable. Upon update of the DOB, I would like the age to be calculated. If someones birthday is 11/9/1990, then as of today, the age should read 16, not 17 because they do not turn 17 until november 9th.
Apr 3 '07 #1
8 3605
Denburt
1,356 Expert 1GB
DateDiff Function
Returns a Variant (Long) specifying the number of time intervals between two specified dates.
Apr 3 '07 #2
missinglinq
3,532 Expert 2GB
Having been birthed on 11/09; well, we won't get into the year! Let's just say I've got shoes older then 1990 that aren't even broken in yet! I had to figure this out!

Expand|Select|Wrap|Line Numbers
  1.  Age = (datediff("m","11/9/1990",now) - datediff("m ","11/9/1990",now)mod 12)/12
will yield 16, not 17!

Good Luck!
Apr 3 '07 #3
jl2886
83
but...If someones birthday is after the current date, it will report the age to be 1 year higher than it is

DateDiff Function
Returns a Variant (Long) specifying the number of time intervals between two specified dates.
Apr 3 '07 #4
jl2886
83
I get "the value you entered isn't valid for the field"
Apr 3 '07 #5
jl2886
83
[code]
Private Sub Date_of_Birth_AfterUpdate()
Me.Age = DateDiff(m, Me.Date_of_Birth, Now) - (DateDiff(m, Me.Date_of_Birth, Now) Mod 12)
End Sub
[\code]
yields invalid procedure
Apr 3 '07 #6
Denburt
1,356 Expert 1GB
You were missing some quotes around your months. "m"

Here is another way...
Expand|Select|Wrap|Line Numbers
  1. DateDiff("yyyy", #11/12/1990#, Date) - IIf(Date < DateSerial(Year(Date), Month(#11/12/1990#), Day(#11/12/1990#)), 1, 0)
Apr 3 '07 #7
missinglinq
3,532 Expert 2GB
As Denburt pointed out, you omitted the quatation marks around the month qualifier ( should be "m" not just m) but you also left off part of the formula! You have to be careful, when copying from the code inset on the forum, to make sure you get all the code that may be beyond the visible part!
Your code should be:

Private Sub Date_of_Birth_AfterUpdate()

Me.Age = (DateDiff("m", Me.Date_of_Birth,Now) - DateDiff("m", Me.Date_of_Birth,Now) Mod 12)/12

End Sub
Apr 4 '07 #8
Corster
36
Here's another way, without using DateDiff, supposing you're using some form of VB:


Private Sub [Your Control] On Update
vblAge = Format(Now - CDate(vblDOB), "yyyy")
End Sub

If you're using Access, it will be Format$(...)

Dunno how accurate it will be though.
Apr 4 '07 #9

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

Similar topics

20
by: Gav | last post by:
I have a database with date of births stored dd/mm/yyyy (english dating system) and =date() returns a date in the same format in my server. how do i find the persons age using these two pieces of...
16
by: KL | last post by:
I am working on a problem and desperately need help! I need to prompt a user for the numerical month of birth, day of birth and year of birth and store it in varialbes and the use the variables...
3
by: Lyn | last post by:
Hi, I am developing a project in which I am checking for records with overlapping start/end dates. Record dates must not overlap date of birth, date of death, be in the future, and must not...
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...
3
by: C Villalba | last post by:
Birth Date and a Purchase Date aata is being stored in sql. This information is retrieved across time zones through a .Net Web Service. When the data is viewed in a .Net client application these...
4
stormrider
by: stormrider | last post by:
Hi all, I'm trying to implement a Perl structure. My small program will do the followings; Take the birth date of the user as input. (Month's will be input as strings.) Take the current time...
2
by: Matuag | last post by:
Hi All, I am trying to create a form which can calculate with Age and Birth Date fields. I want Age to be calculated based on Birth Date (which I managed to do) but at the same time if Birth...
3
by: jamieharrop | last post by:
Afternoon all, I've been battling with this all day today and my brain is now pretty much fried. I have one table that lists several details about my customers (name, address, phone, date of...
1
by: jocelyn88 | last post by:
I would like to identify the Date of Birth, Gender and Age of a Malaysian by extraction the information from the new IC number. The object calculate the Date of Birth, Gender and Age. For example,...
1
by: karimufeed | last post by:
I am working on an access project for pension calculation. I want to generate the retirement date automatically at the age of 60 years while filling the date of Birth. i.e. if the Date of birth is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.