Convert DateTime to nvarchar, only month and year

How to convert datetime value to nvarchar and want to format it "Month, year" eg October 1, 2009, the value should be converted to "October 2009"

+3
source share
5 answers

use this:

select CONVERT(nvarchar(50),   DATENAME(m, getdate()) 
                               + ', ' 
                               + DATENAME(yyyy, getdate())
              )

OUTPUT:

--------------------------------------------------
October, 2009

(1 row(s) affected)
+5
source

try it

DECLARE @DateTime DATETIME

SET @DateTime = '01 Oct 2009'

SELECT @DateTime

SELECT DATENAME(mm, @DateTime) + ', ' + CAST(DATEPART(yy, @DateTime) AS VARCHAR(4))
+1
source

- - , , :

Convert (nvarchar, datename (m, getdate())) + N ',' + Convert (nvarchar, datename (, GETDATE()))

getdate() / .

0

DateName :

DATENAME(m, date) + ', ' + DATENAME(yyyy, date)

nvarchar :

CAST(value AS nvarchar[30])
0
source

Try the following query:

Select case  Convert(int, day(getdate())) when 1 then '1st' when 2 then '2nd'
 when 3 then '3rd' else Convert(varchar, day(getdate()))+'th' end +' '+ Convert(varchar, Datename(m,getdate()))+' ' +Convert(varchar, Datename(yy,getdate()))  as Date

You can replace getdate () with any other date.

Please check if it helps.

0
source

Source: https://habr.com/ru/post/1719000/


All Articles