SQL select query for the number of days from the date of registration

SQL select a query for the number of days from the date of registration. I have a RegistrationDate column in my table Registrationin my SQL Server 2008 database.

Suppose I have registrationDate:

2016-12-10

and suppose this is today 2016-12-20, then the conclusion should look like this:

registrationDate     registrationAge     
  2016-12-10             10 days
+4
source share
1 answer

You can use datediff:

select registrationDate,
  datediff(day, cast(registrationDate as date), getdate()) + ' days' as registrationAge 
from table
+2
source

Source: https://habr.com/ru/post/1665311/


All Articles