List:General Discussion« Previous MessageNext Message »
From:Graeme B. Davis Date:June 27 2000 3:37pm
Subject:Re: Calculating Age
View as plain text  
you could do something like:

SELECT (TO_DAYS(NOW())-TO_DAYS('YYYY-MM-DD'))/365;

or for just a whole number:

SELECT ROUND((TO_DAYS(NOW())-TO_DAYS('YYYY-MM-DD'))/365);

My birthday, for example:

SELECT ROUND((TO_DAYS(NOW())-TO_DAYS('1975-6-17'))/365);
+--------------------------------------------------+
| ROUND((TO_DAYS(NOW())-TO_DAYS('1975-6-17'))/365) |
+--------------------------------------------------+
|                                               25 |
+--------------------------------------------------+
1 row in set (0.00 sec)

I'm sure there are 4 other ways to do this as well =)

Graeme



----- Original Message ----- 
From: "Ben Ocean" <beno@stripped>
To: <mysql@stripped>
Sent: Tuesday, June 27, 2000 10:30 AM
Subject: Calculating Age


> Hi;
> I have a variable called $birth which is the age of a horse in YYYY-MM-DD 
> format. How can I calculate the present age of the horse? TIA,
> BenO
> 
> 
> -- 
> ---------------------------------------------------------------------
> Please check "http://www.mysql.com/php/manual.php3" before
> posting. To request this thread, e-mail mysql-thread41751@stripped
> 
> To unsubscribe, send a message to:
>     <mysql-unsubscribe-GraemeD=uu.net@stripped>
> 
> 

Thread
Calculating AgeBen Ocean27 Jun
  • Re: Calculating AgeGraeme B. Davis27 Jun