Page 1 of 1

Calculate Date of Birth?

Posted: Fri Mar 26, 2010 10:42 am
by adilmarwat2004
I have database in mysql and has a table name "act" contains four fields as

id(int), date_birth(date), date_close(date), age(date)
1 03-09-1987 20-03-2010
2 05-06-1989 20-03-2010

I want that set the query for age field like that it takes date from field 'date_close' and subtract it from 'date_birth' and display in age field.

How it is possible, please help?

Adil

Re: Calculate Date of Birth?

Posted: Fri Mar 26, 2010 11:36 am
by Christopher
Convert them both to timestamps (strtotime() ?), subtract, and then convert back to year, months and days (from seconds).

Re: Calculate Date of Birth?

Posted: Fri Mar 26, 2010 1:47 pm
by josh
http://dev.mysql.com/doc/refman/5.1/en/ ... tions.html
DATE_SUB() or subtract... the second column's timestamp divided by the number of seconds in a day could be a possible subtractor.

DATE_SUB(date,INTERVAL expr unit)

so start_date would be the date paramater
the unit would be days
and the timestamp could be used to calculate how many days you are subtracting..

just one possible way.