At 21:25 +0100 3/30/02, Roger Baklund wrote:
>* Son Nguyen
>> ==> I tried this query, but... it's not working out:
>> SELECT YEAR(now()-birthday) from users where loginName="test";
>
>You are very close:
>
>SELECT YEAR(now())-YEAR(birthday) as age from users where loginName="test";
That won't adjust for the relative difference within the calendar
year of the two dates. This works better:
mysql> SELECT
-> YEAR(CURDATE()) - YEAR(birthday)
-> - IF(RIGHT(CURDATE(),5) < RIGHT(birthday,5),1,0)
-> AS 'age in years'
-> FROM users WHERRE loginName="test";
>
>--
>Roger
>query
| Thread |
|---|
| • LIMIT, ORDER Dilema | destr0 | 30 Mar |
| • Re: LIMIT, ORDER Dilema | Tyler Longren | 30 Mar |
| • Re: LIMIT, ORDER Dilema | Paul DuBois | 30 Mar |
| • Re: LIMIT, ORDER Dilema | destr0 | 30 Mar |
| • Re: LIMIT, ORDER Dilema | Paul DuBois | 30 Mar |
| • Re: LIMIT, ORDER Dilema | destr0 | 30 Mar |
| • Re: LIMIT, ORDER Dilema | Paul DuBois | 30 Mar |
| • RE: LIMIT, ORDER Dilema | Roger Baklund | 30 Mar |
| • RE: LIMIT, ORDER Dilema | Paul DuBois | 30 Mar |
| • Calculate current age with given birthday | Son Nguyen | 30 Mar |
| • RE: Calculate current age with given birthday | Roger Baklund | 30 Mar |
| • RE: Calculate current age with given birthday | Paul DuBois | 30 Mar |
| • RE: Calculate current age with given birthday | Michael Stassen | 30 Mar |
| • Re: LIMIT, ORDER Dilema | Steven Roussey | 30 Mar |
| • RE: Calculate current age with given birthday | Paul DuBois | 31 Mar |
| • RE: Calculate current age with given birthday | Michael Stassen | 2 Apr |