Skip to content

Instantly share code, notes, and snippets.

@patmanv
Created August 25, 2014 09:50
Show Gist options
  • Select an option

  • Save patmanv/17a3b50ba80dda26ffc2 to your computer and use it in GitHub Desktop.

Select an option

Save patmanv/17a3b50ba80dda26ffc2 to your computer and use it in GitHub Desktop.
Current Age (sql)
DECLARE @startDate DATETIME = '20130703'
DECLARE @endDate DATETIME = '20140703'
IF ((MONTH(@endDate) * 100 + DAY(@endDate)) - (MONTH(@startDate) * 100 + DAY(@startDate))) >= 0
SELECT DATEDIFF(YEAR,@startDate, @endDate)
ELSE
SELECT DATEDIFF(YEAR,@startDate, @endDate) - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment