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
Calculate Date of Birth?
Moderator: General Moderators
-
adilmarwat2004
- Forum Commoner
- Posts: 44
- Joined: Fri Sep 04, 2009 11:28 pm
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Calculate Date of Birth?
Convert them both to timestamps (strtotime() ?), subtract, and then convert back to year, months and days (from seconds).
(#10850)
Re: Calculate Date of Birth?
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.
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.