Question

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,

Was it helpful?

Solution

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())

OTHER TIPS

SELECT CONVERT(VARCHAR,GETDATE(),106)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top