how to subtract column date with system date?

0

I have a column with date data_novo and I want to know how many days the product is open, I have to make a subtraction count between the "system date" and the date it is in the data_novo column. And this result will be displayed in another column (eg open days). How can I do this?

I've tried the following:

diferença= DATETIME-DAT_ABER

I have no idea how. Can you help me please?

    
asked by anonymous 11.06.2018 / 21:20

1 answer

1

You can use the DATEDIFF function of sql server:

SELECT DATEDIFF(day,startDate,endDate) AS 'Duration'  
FROM dbo.Duration; 

In this case it calculates the difference of days between two dates.

    
11.06.2018 / 21:25