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).
In the previous article I have explained How to generate barcode in asp.net, Sqlserver query to get exact DOB in Years, months and days and Show and hide divon one button Click using jquery.
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.