PDA

View Full Version : Microsoft Access 2000


victoria_1018
09-04-2002, 09:11 AM
Hi,
I am creating a staff table using MS 2000. There is one area I am not sure how to do.

There are these two fields, DOB (Day of Birth) and Age in my database. My question is what must I do to the database so that my age field is auto generate by the year now (2002) minus by the year the user was born?

Thanks
Regards
victoria

Mhtml
09-04-2002, 10:05 AM
Is going to be on the web? Or in an ASP page to be more precise?

If it is then getting ASP to do the calculation is easier..

But this sought of thing is best suited to excel.

I've attached an EXCEL spread sheet which does this, you can probably insert this into the acces database if you want.

victoria_1018
09-04-2002, 10:51 AM
Can I just have this done in MS Access Itself and it will also calculate his age (including month and days).
ps: The whole program is done in Microsoft Access 2000.

Brad
09-04-2002, 01:27 PM
Victoria,

If you need it to calculate in the ASP page itself, you could try something like the following (I used this for an asset depreciation report recently):

regdate= objrs("Date_Of_Registration")
age = DateDiff("yyyy", regdate, Now)

so, regdate is the date of birth field

age is the difference between regdate and the current date (here, i've specified it look at the year part of the date string).

So you could do

dob = objrs("birthday")
age = datediff("yyyy"), dob, Now)

It may need fiddling with a bit, but that should do the trick.
Would mean you wouldn't need to include the field in your original database aswell.

Hope this helps,
Brad.

Brad
09-04-2002, 01:32 PM
If you want to create the age in access2000 directly, use an expression in a query like:

Expr1: DateDiff("yyyy",[date],Now())

so you'd have the details from the table in the query as columns, then in a new column, the above expression.

Brad.

raf
09-04-2002, 01:50 PM
you can do this in access by using a macro. the access helppages tell you how.

you'd probably best use the datedif-function (which computes the interval between two dates)

this is a server-sided forum, so unless you wan't to do this in asp, your a bit off track ...

Mhtml
09-06-2002, 09:14 AM
that's exactly what I meant, you should probably find an access forum as they would no doubt have more knowledge floating around...(I know that was a rash generalisation but I mean on average)