Friday, September 24, 2004

Nothing says it better then SQL

When you have nothing to say it is best to just keep quiet. Alternatively, just say something in SQL code. As writing this simple SQL query kept me amused for nearly half a minute at work I thought I would share it in a more abstract form.

SELECT datefield
FROM sometabel
WHERE WEEK(CONCAT(DATE_FORMAT(NOW(),'%Y-'), DATE_FORMAT(datefield,'%m-%d'))) = WEEK(NOW())
ORDER BY DATE_FORMAT(datefield,'%d')

Always handy when you need to match all fields who's datefield is in the same week as the one your currently in (if your using MySQL that is). And you happen to want to order it according to the days in that week.

0 Comments:

Post a Comment

<< Home