EKBG
EKBG

Reputation: 253

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.date)) AND YEAR(S.date) = '$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"

Upvotes: 2

Views: 3406

Answers (2)

Oliver
Oliver

Reputation: 883

your Mysql-Query is false. Try this:

..WHERE MONTHNAME(MONTH(S.date)) = '$date->MONTHNAME' AND YEAR(S.date) = '$date->Year'..

Upvotes: 2

ScaisEdge
ScaisEdge

Reputation: 133370

You could use concat

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

Upvotes: 1

Related Questions