Forums

This topic is locked

SQL Filter Current Month Statement

Posted 14 years ago
1
has voted
14 years ago 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 14 years ago
14 years ago 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 14 years ago
14 years ago Nathan M replied:
I came up with this:

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

Reply to this topic