Forum Moderators: coopster & phranque

Message Too Old, No Replies

Date Query

best method?

         

lorax

4:10 pm on Aug 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello Folks,
I need to check for entries in a db with dates that match the current month (or whatever month I tell it to look for). I'm hoping there's an easy way to use the where clause to do this. I know I can pass the query the current month but can I/how do I, tell the query to compare this with the month from the date field (which is a full SQL date/time) in the db?

Your thoughts?

Knowles

4:23 pm on Aug 26, 2002 (gmt 0)

10+ Year Member




MONTH(date)
Returns the month for date, in the range 1 to 12:

mysql> SELECT MONTH('1998-02-03');
-> 2


Would something like this work? You could select it WHERE MONTH=2?

came from 6.3.4 Date and Time Functions [mysql.com]

lorax

4:33 pm on Aug 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



DOH!
I shoulda thought to look at MySQL.com myself. That's exactly what I was looking for. Thanks.

GB

Knowles

4:42 pm on Aug 26, 2002 (gmt 0)

10+ Year Member



This is where I get excited because I was right right? ;)

lorax

5:04 pm on Aug 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yup. Works like a charm.

1 attaboy for you. :)