Sql server: Convert total number of days into month(s) and day(s) - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

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) ')
  



What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+


EmoticonEmoticon