Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert datetime to month in number and year

I have a datetime e.g. 2014-04-24 00:28:53.897 and want to convert this in a select query to month in number and year - 4 2014.

like image 875
Sven Müller Avatar asked May 11 '15 08:05

Sven Müller


2 Answers

Try this

SELECT FORMAT(GETDATE(),'MM yyyy')

replace getdate with you datetime column

Hope it help you.

like image 151
Chanom First Avatar answered Nov 01 '22 06:11

Chanom First


Use DATEPART

SELECT CONCAT(DATEPART(mm,datefield),' ',DATEPART(yyyy,datefield)) AS monthyear
FROM yourtable

SQL FIDDLE: http://sqlfiddle.com/#!6/9c896/7/0

like image 35
Matt Avatar answered Nov 01 '22 06:11

Matt