EKBG EKBG - 27 days ago 14
PHP Question

Convert datetime to get month name in mysql

Datetime column data is as

2016-11-03 00:00:00
. I want to get month and year from this and convert month number as month name.

E.g.:

2016-11-03 00:00:00
--> November 2016

Code Snippet



..WHERE MONTHNAME(MONTH(S.mydate)) AND YEAR(S.mydate) = '$date'..


Month year picker code



This outputs month/year format as "November 2016".

if(isset($_POST['monthPicker'])){$date = $_POST['monthPicker'];}


Database column name for datetime is "S.date"

Answer

You could use concat

"select ..... 
 ...
where concat(MONTHNAME(S.date), ' ' , YEAR(S.date))  = '$date';"
Comments