'2 года -2 месяца 21 день' почему я получаю минус, когда возвращаю month-DATEDIFF
Когда я выполнил свой запрос, я получил минус с месяцем ! Может ли кто-нибудь указать мне правильное направление? Спасибо.
SELECT CAST(DATEDIFF(yy, WorkStartDate, GETDATE()) AS varchar(4)) +' year '+ CAST(DATEDIFF(mm, DATEADD(yy, DATEDIFF(yy, WorkStartDate, GETDATE()), WorkStartDate), GETDATE()) AS varchar(2)) +' month '+ CAST(DATEDIFF(dd, DATEADD(mm, DATEDIFF(mm, DATEADD(yy, DATEDIFF(yy, WorkStartDate, GETDATE()), WorkStartDate), GETDATE()), DATEADD(yy, DATEDIFF(yy, WorkStartDate, GETDATE()), WorkStartDate)), GETDATE()) AS varchar(2)) +' day' as result FROM dbo.Paychecks INNER JOIN dbo.Users ON Users.Id=Paychecks.UserId WHERE Users.CustomerId=214 order by Users.FirstName;
Что я уже пробовал:
SELECT CAST(DATEDIFF(yy, WorkStartDate, GETDATE()) AS varchar(4)) +' year '+ CAST(DATEDIFF(mm, DATEADD(yy, DATEDIFF(yy, WorkStartDate, GETDATE()), WorkStartDate), GETDATE()) AS varchar(2)) +' month '+ CAST(DATEDIFF(dd, DATEADD(mm, DATEDIFF(mm, DATEADD(yy, DATEDIFF(yy, WorkStartDate, GETDATE()), WorkStartDate), GETDATE()), DATEADD(yy, DATEDIFF(yy, WorkStartDate, GETDATE()), WorkStartDate)), GETDATE()) AS varchar(2)) +' day' as result FROM dbo.Paychecks INNER JOIN dbo.Users ON Users.Id=Paychecks.UserId WHERE Users.CustomerId=214 order by Users.FirstName;