Forums

This topic is locked

SQL Filter Current Month Statement

Posted 17 Apr 2011 19:02:57
1
has voted
17 Apr 2011 19:02:57 Nathan M posted:
I've been working on this for weeks, searching forums and trying scripts and I haven't found anything to work yet. I have a field set up in MYSQL database called date and it is in date format. All I need to do is create a simple statement in the where clause to filter out this months date to be displayed on a PHP page.

I've Tried:

WHERE (MONTH(Date)) = @MonthPara)

and

where Date >= @FirstDayOfMonth and Date < @FirstDayOfNextMonth


and several others. Nothing seems to work

Replies

Replied 18 Apr 2011 11:16:32
18 Apr 2011 11:16:32 Patrick Woldberg replied:
Not sure what you want, seeing your examples I guess you want to query the results for a given month.

The second should work, the first could work but you should also include the year in it.

SELECT * FROM `table` WHERE MONTH(Date) = @Month AND YEAR(Date) = @Year
Replied 24 Apr 2011 03:08:41
24 Apr 2011 03:08:41 Nathan M replied:
I came up with this:

WHERE month(datefieldfromdatabase) = MONTH( NOW())

Reply to this topic