How to get year , month, date from days in sql server 2005?
Given a number as 269 or 456.. 开发者_StackOverflowhow can I get the year, month and days using a single line sql function.. if possible?
Thanks
How about
SELECT DATEADD(day, 0, 456)
OK, seriously how about
SELECT DATEADD(day, 0, 456) DateVal,
DATEDIFF(year,0,DATEADD(day, 0, 456)) YearPart,
DATEPART(month,DATEADD(day, 0, 456)) MonthPart,
DATENAME(month,DATEADD(day, 0, 456)) MonthNamePart,
DATEPART(day,DATEADD(day, 0, 456)) DayPart
Output
DateVal YearPart MonthPart MonthNamePart DayPart
1901-04-02 00:00:00.000 1 4 April 2
精彩评论