I have a table in mySQL:
---Dogs---
id int
birthdate date
On average, a dog adds 7 years to its life, every year.
Basically I would like to know if today is the dog’s actual birthday or if it’s their dog birthday. It’s approximately 52 days between each dog birthday. I can’t figure out how to write this query at all.
I would like rows returned that would look like this:
|-----------------|
| id | birthdate |
|-----------------|
| 40 | 2003-12-08 |
| 59 | 2007-12-08 |
| 87 | 2005-06-07 | <-
| 33 | 2009-11-05 | <- Not sure if these would be accurate but want them to
| | | return if today worked out being their 'dog birthday'
Also, their actual birthdate is much more important to me. I don’t want to rely on a date_diff calculation. Where birthdate = today OR birthdate = calculated date.
I think I peiced it together. I did this and it seems to be working the way I want:
select distinct(d.id) from Dogs d
where MONTH( CURDATE( ) ) = MONTH( d.birthdate )
AND DAYOFMONTH( CURDATE( ) ) = DAYOFMONTH( d.birthdate )
or
datediff (curdate(), d.birthdate) % 52 = 0
Use modulus :-