Skip to content
Advertisement

Subtract today’s date with date column in SQL [closed]

I have a column in SQL item_expired, this column stores data in the form of dates from other items. What I want to ask, how do I subtract existing date in item_expired column with the current date, which will then be stored in the remaining_time column.

I’ve tried the command below, but isn’t working:

SELECT
    item_description, item_expired,      
    item_date = DATEDIFF(DAY, CURRENT_TIMESTAMP, item_expired) 
FROM Customers;

Advertisement

Answer

As GMB has mentioned in the comment above, date functions depend on the database type you are using. Assuming you are asking about MySQL the below query will provide you with the remaining time required.

select 
    (CURRENT_DATE - item_expired) as remaining_time 
from customers;

While this will provide you with the remaining time, you will have to write a separate insert to insert the remaining time for the table column.

6 People found this is helpful
Advertisement