How to return a date format similar to 7-Feb-2012 using TSQL?
Pregunta
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,
Solución
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())
Otros consejos
SELECT CONVERT(VARCHAR,GETDATE(),106)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow