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.
Try this
SELECT FORMAT(GETDATE(),'MM yyyy')
replace getdate with you datetime column
Hope it help you.
Use DATEPART
SELECT CONCAT(DATEPART(mm,datefield),' ',DATEPART(yyyy,datefield)) AS monthyear
FROM yourtable
SQL FIDDLE: http://sqlfiddle.com/#!6/9c896/7/0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With