Question:
How to Calculate Age in Microsoft Access: Not Just the Formulas, Please!?
workingsucks2
2011-07-22 00:13:17 UTC
This is the formula I have found online: =DateDiff("yyyy", [Birthdate], Now())+ Int( Format(now(), "mmdd") < Format( [Birthdate], "mmdd") )

That's all very well and good, but I don't know what to put into the quotation marks, brackets, etc. I don't know if I'm supposed to take out the "now" in parantheses and put something else in. What year goes first? I literally don't know how to do anything, other than put in the recognized field of BDate (in my database) where Birthdate goes in the expression. I'm using the expression builder.

If someone knows of a simpler way to do this, and can also tell me what to actually input, using a fictitious example that would be great!


It's a summer class so we had literally one week to learn how to use Access, combined with an MIA professor and my complete lack of Access knowledge. I'm about to lose it!

Thanks in advance!
Four answers:
2011-07-23 17:45:49 UTC
Hopefully this helps some:

(Explanation followed by Example)



*Explanation of the code you found:

=DateDiff("yyyy", [Birthdate], Now())+ Int( Format(now(), "mmdd") < Format( [Birthdate], "mmdd") )



=DateDiff - This tells Access you want to see the time between two dates that you're about to specify.

"yyyy" - Tells Access the interval of time you're looking for. In this case "yyyy" means you want difference in years. If you wanted difference in months use "m" or days "d" (only one letter for those...years is 4 y's). You DON'T put anything in it's place...if you want your answer as years you leave it as "yyyy".

[BirthDate] - This is your Field Name from your Table for your starting date. In your case as you described above, you would use [BDate] instead of [BirthDate].

Now() - This is pretty literal to Access. It refers to right this moment. You would leave this alone because if you wanted to find how old someone is then you would want to compare their birthday to today.

Int - Basically saying you're dealing with a number.

Format(now(), "mmdd") < Format( [Birthdate], "mmdd") ) - Basically this tells Access you want this expression to take today's date, the Now(), and find the difference with today's date and your Fields date, the [Birthdate] Field column. Again, leave the "mmdd" alone. It tells Access the date format to do the math for you. And yes I know it has double m's and d's when I just mentioned above to use only one of those letters for m or d.....it's a different area and here it's ok.



**Hint: When in Access hit the F1 key to open the help window. Type in the search box that pops up something like Now and it will give you the definition of it and tell you what it does.





***Example of using the code you found:

You are starting with:

=DateDiff("yyyy", [Birthdate], Now())+ Int( Format(now(), "mmdd") < Format( [Birthdate], "mmdd") )



Now, you said your Field Name in your Table was BDate. So lets update our formula:

=DateDiff("yyyy", [BDate], Now())+ Int( Format(now(), "mmdd") < Format( [BDate], "mmdd") )

That's it! Your formula is complete!! Access will do the rest for you!

Here's how:



Again, you said you already have a Table with a Field Name (a vertical column in your Table), labeled:

BDate

So we'll move on.



To get the diff in dates, and to use that data somewhere, you'll need to make a Query:

-In Access 2007 or 2010 with your database open, you can simply click the "Create" tab at the top of the Access program.

-click "Query Design"

-the "Show Table" pop-up box should have opened. Select the Table that contains your BDate Field and hit "Add" to add it to the Query Design window. Close the pop-up box.

-Double click something that identifies who you're calculating age for, such as a Field that contains a contacts name or whatever. Dbl clicking adds that field to the area at the bottom.

-Double click the "BDate" Field name to also add it to the bottom so you can see the birthdate when the fields are calculated for you.

-In the area at the bottom you should have several blank columns next to the information you just added to it. In the next available blank column, in the first row (Field), copy and paste your formula in: =DateDiff("yyyy", [BDate], Now())+ Int( Format(now(), "mmdd") < Format( [BDate], "mmdd") )

-Make sure the "Show" box is checked a few rows down so you can see your answer.

-Save your Query, and hit Run. You should see your ages next to your BDate.

-Use the results of the Query in other areas like Forms, etc.
?
2016-11-16 20:08:32 UTC
Calculate Age In Access
Kaushik
2014-03-29 09:41:42 UTC
I know that if 1st january 1986 a man born then his date of retirement is 31st december 2046 when retirement age is 60 years so what is the query formula in Ms access? Please help me
2016-03-18 02:04:17 UTC
If A1 is the person's date of birth (say, August 15, 2000), and today is Sep 19, 2008: =DATEDIF(A1,TODAY(),"y") result: 8 =DATEDIF(A1, TODAY(), "ym") result: 1 =DATEDIF(A1, TODAY(), "md") result: 4 The person is 8 years, 1 month, and 4 days old. Excel will factor in the leap days. =DATEDIF(A1,TODAY(),"d") result: the person is 2957 days old.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...