Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>create procedure getDatedifference ( @startdate datetime, @enddate datetime ) as begin declare @monthToShow int declare @dayToShow int --set @startdate='01/21/1934' --set @enddate=getdate() if (DAY(@startdate) &gt; DAY(@enddate)) begin set @dayToShow=0 if (month(@startdate) &gt; month(@enddate)) begin set @monthToShow= (12-month(@startdate)+ month(@enddate)-1) end else if (month(@startdate) &lt; month(@enddate)) begin set @monthToShow= ((month(@enddate)-month(@startdate))-1) end else begin set @monthToShow= 11 end -- set @monthToShow= convert(int, DATEDIFF(mm,0,DATEADD(dd,DATEDIFF(dd,0,@enddate)- DATEDIFF(dd,0,@startdate),0)))-((convert(int,FLOOR(DATEDIFF(day, @startdate, @enddate) / 365.25))*12))-1 if(@monthToShow&lt;0) begin set @monthToShow=0 end declare @amonthbefore integer set @amonthbefore=Month(@enddate)-1 if(@amonthbefore=0) begin set @amonthbefore=12 end if (@amonthbefore in(1,3,5,7,8,10,12)) begin set @dayToShow=31-DAY(@startdate)+DAY(@enddate) end if (@amonthbefore=2) begin IF (YEAR( @enddate ) % 4 = 0 AND YEAR( @enddate ) % 100 != 0) OR YEAR( @enddate ) % 400 = 0 begin set @dayToShow=29-DAY(@startdate)+DAY(@enddate) end else begin set @dayToShow=28-DAY(@startdate)+DAY(@enddate) end end if (@amonthbefore in (4,6,9,11)) begin set @dayToShow=30-DAY(@startdate)+DAY(@enddate) end end else begin --set @monthToShow=convert(int, DATEDIFF(mm,0,DATEADD(dd,DATEDIFF(dd,0,@enddate)- DATEDIFF(dd,0,@startdate),0)))-((convert(int,FLOOR(DATEDIFF(day, @startdate, @enddate) / 365.25))*12)) if (month(@enddate)&lt; month(@startdate)) begin set @monthToShow=12+(month(@enddate)-month(@startdate)) end else begin set @monthToShow= (month(@enddate)-month(@startdate)) end set @dayToShow=DAY(@enddate)-DAY(@startdate) end SELECT FLOOR(DATEDIFF(day, @startdate, @enddate) / 365.25) as [yearToShow], @monthToShow as monthToShow ,@dayToShow as dayToShow , convert(varchar,FLOOR(DATEDIFF(day, @startdate, @enddate) / 365.25)) +' Year ' + convert(varchar,@monthToShow) +' months '+convert(varchar,@dayToShow)+' days ' as age return end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload