Reputation: 37
I have "datetime" field on my database, but what I want is only take YEAR-MONTH e.g ("2012-02")
I've tried using function YEAR_MONTH but the output without "-" which is similar like "201202".
Is there any way I could make that select?
Upvotes: 2
Views: 4815
Reputation: 1477
You want to give False in second Param in Select
select("DATE_FORMAT(now(), '%Y-%m') AS dated_now", FALSE);
Upvotes: 1
Reputation: 63
Try this
SELECT DATE_FORMAT(now(),'%Y %m');
You can also check the below link
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
Upvotes: 0
Reputation: 311228
You can use the date_format
function to specify how to format your columns:
SELECT DATE_FORMAT(my_datetime_field, '%Y-%m')
FROM my_table
Upvotes: 2