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.
8 3605
DateDiff Function
Returns a Variant (Long) specifying the number of time intervals between two specified dates.
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! - Age = (datediff("m","11/9/1990",now) - datediff("m ","11/9/1990",now)mod 12)/12
will yield 16, not 17!
Good Luck!
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.
I get "the value you entered isn't valid for the field"
[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
You were missing some quotes around your months. "m"
Here is another way... - DateDiff("yyyy", #11/12/1990#, Date) - IIf(Date < DateSerial(Year(Date), Month(#11/12/1990#), Day(#11/12/1990#)), 1, 0)
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
| |