473,396 Members | 1,895 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,396 software developers and data experts.

Calculating an age from a DoB in an Access table

tkq
I have a normal table with customer information

I have a DoB field and I want to have an automatic calculation that will show
the age of the customer in another field next to it called Age

Could you please help me with this

Thanx all
Apr 3 '06 #1
10 47672
Age: (Now()-[Birth Date])/365.25

tkq wrote:
I have a normal table with customer information

I have a DoB field and I want to have an automatic calculation that will show
the age of the customer in another field next to it called Age

Could you please help me with this

Thanx all


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200604/1
Apr 3 '06 #2
tkq
I tried what you suggested but this error message comes up

"Invalid SQL syntax - cannont use multiple columns in a column-level CHECK
constraint."

Do you know how to overcome this
Apr 3 '06 #3
On Mon, 03 Apr 2006 13:05:31 GMT, tkq wrote:
I have a normal table with customer information

I have a DoB field and I want to have an automatic calculation that will show
the age of the customer in another field next to it called Age

Could you please help me with this

Thanx all


In a query:
Age: DateDiff("yyyy", [DOB], Date()) - IIF(Format([DOB], "mmdd") >
Format(Date(), "mmdd"), 1, 0)

Directly as the control source of an unbound control:
=DateDiff("yyyy",[DOB],Date())-IIf(Format([DOB],"mmdd")>Format(Date(),
"mmdd"),1,0)

You do know, I hope, that this Age computation should NOT be stored in
any table.
Just compute it and display it on a form or report, as needed.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Apr 3 '06 #4
"tkq" <u20428@uwe> wrote in news:5e3a073204b88@uwe:
I tried what you suggested but this error message comes up

"Invalid SQL syntax - cannont use multiple columns in a
column-level CHECK constraint."

Do you know how to overcome this


You are trying to store the data at the table level. You need to
enter the formula in any of a query, a form or a report. It makes
no sense to store it in the table because it will need to be
recalculated every time you open the table, or any query based on
that table.

So to overcome this, remove the field 'age' from the table and put
it wherever you use to display the age.

--
Bob Quintal

PA is y I've altered my email address.
Apr 3 '06 #5
tkq wrote:
I have a normal table with customer information

I have a DoB field and I want to have an automatic calculation that will show
the age of the customer in another field next to it called Age

Could you please help me with this

Thanx all


In a query:

SELECT Int(Format(Date(),"yyyy.mmdd") -
Format([BirthDate],"yyyy.mmdd")) AS AgeNow FROM tblBirthdays;

Note that the double quotes above can be converted to single quotes
when a dynamic SQL string is being created.

As a Control Source:

=Int(Format(Date(),"yyyy.mmdd") - Format([BirthDate],"yyyy.mmdd"))

Note that Null values for [BirthDate] aren't handled here. For your
example, replace AgeNow with Age and replace [BirthDate] with your DoB
field name. I have used a similar technique for calculating elapsed
months using "mm.dd" with the Format command as part of the
calculation.

James A. Fortune
CD********@FortuneJames.com

Apr 4 '06 #6
To extend this a little bit.

Can have a query some thing like

SELECT tblBirthdays.*, Int(Format(Date(),"yyyy.mmdd") -
Format([tblBirthdays.BirthDate],"yyyy.mmdd")) AS AgeNow FROM
tblBirthdays

You will get everything in your table plus a calculated Age column.

-Saran

Apr 4 '06 #7
Saran wrote:
To extend this a little bit.

Can have a query some thing like
Where in the query would I write this. That is the only thing i'm not sure of

SELECT tblBirthdays.*, Int(Format(Date(),"yyyy.mmdd") -
Format([tblBirthdays.BirthDate],"yyyy.mmdd")) AS AgeNow FROM
tblBirthdays

You will get everything in your table plus a calculated Age column.

-Saran


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200604/1
Apr 4 '06 #8
tkq via AccessMonster.com wrote:
Saran wrote:
To extend this a little bit.

Can have a query some thing like


Where in the query would I write this. That is the only thing i'm not sure of


There's a SQL View for queries. Paste the text into the SQL View
window. I usually put a semicolon at the end of the SQL text.

James A. Fortune
CD********@FortuneJames.com

Apr 4 '06 #9
CD********@FortuneJames.com wrote:
>To extend this a little bit.
>
>Can have a query some thing like


Where in the query would I write this. That is the only thing i'm not sure of


There's a SQL View for queries. Paste the text into the SQL View
window. I usually put a semicolon at the end of the SQL text.

James A. Fortune
CD********@FortuneJames.com


Thanks very much, I've got it to work now
Thanks to all who helped aswell
Much Appreciated

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200604/1
Apr 5 '06 #10
Another way of doing this is to divide by the real number of days in a
year then round down. Thus the difference between date 1 and date 2...

YearsDiff = Int(([d2]-[d1])/365.242)

MonthDiff = ([d2]-[d1])/(365.242/12) Mod 12

Apr 10 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John | last post by:
hey all..... alright, I am frusterated to the point of throwing my machine out the window (this board went down, trying to find stuff on google, this has been a nightmare) so I hope you guys can...
1
by: Heath | last post by:
I have serious Access problems so please be gentle. I have one table that stores the quantities and net sales for thousands of Products. I have another table that has fixed costs values on a...
7
by: JLM | last post by:
I have a table that has fieldA, fieldB, fieldC. I want fieldC=fieldA-fieldB. simple enough. the next record I want to be able to do the same on the new value of fieldC. I can do this with SAP...
1
by: Alex | last post by:
Hi all, In Microsoft Access 2000, how do I tell a query to count a null as zero? I'm adding several columns of data, and many contain nulls, but that makes my results be null as well. Is there...
3
by: luscus | last post by:
Thanks for all the responses on my first question. Unfortunately the answers I was given were too complicated for my small brain , and neophite condition to understand. So if you could talk down to...
2
by: kuhni | last post by:
Hi everybody! After searching newsgroups for a couple of hours, I now try asking directly (running the risk of asking again the same question). My problem is to predict when the size of the...
3
by: Wired Hosting News | last post by:
Lets say I have 10 products in 10 different stores and every week I get a report from each store telling me how many items they have left for each of the 10 products. So each week I enter in 100...
5
by: Wired Hosting News | last post by:
I tried to be breif and give a scenario so as not to be overlooked because it was soooo long. Let me give you real world. I am a manufacturer of goods and produce 11 items that are distributed...
8
by: King | last post by:
Hi I have following MS Acess query Here is the query ID Name Prgm ID Client ID Date Start Time End Time Minutes C4 Trisha TIP DEK0703 7 /7 /2006...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.