Domanda

Using TSQL, How to return a date with a format similar to "7-Feb-2012"?

this returns the day:

SELECT DATEPART(d, getdate())

this returns the year:

SELECT DATEPART(yyyy, getdate())

How to return the month name?

Thanks,

È stato utile?

Soluzione

The following will give you the format like "14-Feb-2012":

SELECT REPLACE(CONVERT(VARCHAR(11), GETDATE(), 106), ' ', '-') AS [dd-Mon-YYYY]

If you just want the month name, you can do:

select DATENAME(m, getdate())

Altri suggerimenti

SELECT CONVERT(VARCHAR,GETDATE(),106)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top