Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql: select all entries from a particular month using PHP

Tags:

php

mysql

I have a mysql database table called POST.
One of the fields is a timestamp, set to default to the current timestamp on the mysql server when the record is created.

I need a SQL query to extract all rows that have a timestamp within a particular month. That is, all records for March, or all records for November, etc.

like image 921
Will Gill Avatar asked Mar 27 '11 17:03

Will Gill


1 Answers

you have to use monthname()

select * from thetable where monthname(date_field) = 'February'

or month(), but this function will return a number

select * from thetable where month(date_field) = 2
like image 152
Raffael Avatar answered Sep 23 '22 02:09

Raffael