//// Method 1
DECLARE @getmm INT,@yy int ,@mm int,@dd int,@getdd INT,@dstart datetime='2010-01-01',@dend datetime='2016-06-12'
SET @yy = DATEDIFF(yy, @dstart, @dend)
SET @mm = DATEDIFF(mm, @dstart, @dend)
SET @dd = DATEDIFF(dd, @dstart, @dend)
SET @getmm = ABS(DATEDIFF(mm, DATEADD(yy, @yy, @dstart), @dend))
SET @getdd = ABS(DATEDIFF(dd, DATEADD(mm, DATEDIFF(mm, DATEADD(yy, @yy, @dstart), @dend), DATEADD(yy, @yy, @dstart)), @dend))
select 'Year : '+ Convert(varchar(10),@yy) + ', ' +'Month : '+ Convert(varchar(10),@getmm) + ', '
+ 'Days : '+Convert(varchar(10),@getdd)
/// Result
No comments:
Post a Comment