D
D
Dmitry2017-08-07 15:02:39
MySQL
Dmitry, 2017-08-07 15:02:39

How to get month from date?

I make filters on the site, by city, month and day.
For the city, I did the equation WHERE `city` = $_GET['city']
Here is the query itself:

$cat_result = mysqli_query( "SELECT * FROM `poster` WHERE `cat` = '".$cat_q['id']."' AND `city` = '".$_GET['city']."'");

I can’t make the same filter for month and day, because this data is stored in one column of the datetime format and looks like 0000-00-00 00:00:00
Let’s say the date is 2017-09-21 19:00:00 the month of this date 09. I need it = to $_GET['month'] (Month itself = 09) that is, if I equate the request in this form
$cat_result = mysqli_query( "SELECT * FROM `poster` WHERE `cat` = '".$cat_q['id']."' AND `date` = '".$_GET['month']."'");

will not work because it will be like this 2017-09-21 19:00:00 = 09
And I need to select only the month in the query right away.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2017-08-07
@maxdit

Use MONTH .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question