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.
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) ')
No comments:
Post a Comment