Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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,
以下将为您提供类似“2012 年 2 月 14 日”的格式:
SELECT REPLACE(CONVERT(VARCHAR(11), GETDATE(), 106), ' ', '-') AS [dd-Mon-YYYY]
如果您只想要月份名称,您可以执行以下操作:
select DATENAME(m, getdate())
SELECT CONVERT(VARCHAR,GETDATE(),106)