how can i do this?
select * From table_name Where date = currentmonth
when date is a double and i insert it like so date = date("U")
so i want to select the month of date("U") for the current month
how to select current month
Moderator: General Moderators
Re: how to select current month
First of all, "date" is a reserved word and should not be used as the name of a field in a table.
http://developer.mimer.com/validator/sq ... -words.tml
The "U" only refers to the format in which to display a datetime value. All datetime data type fields are stored in the same format.
You can make your comparison like this:
The SQL function month() returns a value from 1 to 12, as does the PHP function date('n'). You can see why using "date" as a field name is bad.
Notice that this only matches the month, not the year, so if your data contains entries for other years and you are only interested in the current month of the current year, you will need to extend the logic to do that.
http://developer.mimer.com/validator/sq ... -words.tml
The "U" only refers to the format in which to display a datetime value. All datetime data type fields are stored in the same format.
You can make your comparison like this:
Code: Select all
$sql = "SELECT * FROM table_name WHERE month(field_name) = ".date('n')Notice that this only matches the month, not the year, so if your data contains entries for other years and you are only interested in the current month of the current year, you will need to extend the logic to do that.