Coding WTF of the day #2.

I came across this snippet today in a site at work.. It triggered an event from last year.. no wonder :\

 
SELECT * FROM event_reminders WHERE DAYOFYEAR(`event_date`)-1 = DAYOFYEAR(CURRENT_DATE())
 

It made me scream a little!!.

Here is my correction. Not sure how people can actually do this sort of thing.

 
SELECT * FROM event_reminders WHERE TO_DAYS(`event_date`)-1 = TO_DAYS(CURRENT_DATE());
 

Another way of displaying this is as follows.

Bad..

 
mysql> select dayofyear('2010-05-26'), dayofyear(now());
+-------------------------+------------------+
| dayofyear('2010-05-26') | dayofyear(now()) |
+-------------------------+------------------+
|                     146 |              146 | 
+-------------------------+------------------+
1 row in set (0.00 sec)
 

Good..

 
mysql> select to_days('2010-05-26'), to_days(now());
+-----------------------+----------------+
| to_days('2010-05-26') | to_days(now()) |
+-----------------------+----------------+
|                734283 |         734648 | 
+-----------------------+----------------+
1 row in set (0.00 sec)
 

Love to hear your thoughts.