Sql server: Convert total number of days into month(s) and day(s)

In this article I am going to explain how to get the number of days between two dates and convert days into month(s) and day(s).

Sql server: Convert total number of days into month(s) and day(s)



Implementation:
I want to convert total number of days into months and days between 2 dates. Here is the query that will work:

SET DATEFORMAT dmy;

declare @start date ='01/07/2016'
declare @end date ='03/09/2016'

select [MONTH and DAY]=(cast(DATEDIFF(MM,@start,@end) as varchar)+' Month(s) '
+ cast(DATEDIFF(DD, @start, DATEADD(MM, - DATEDIFF(MM, @start, @end),
            @end)) AS varchar) + ' Day(s) ')
  



Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget