Didik Ariyana
Didik Ariyana

Reputation: 39

How to calculate the duration date in SQL or PHP

I want to calculate the remaining duration using an SQL query or using PHP. I have a table that has fields
- date_submit (example 2019-12-01 09:40:22 ) and
- duration ( example 30 days )

For example today is 2019-12-02 so the remaining duration is 29, how can I calculate this in SQL or PHP?

Upvotes: 0

Views: 141

Answers (1)

Nick
Nick

Reputation: 147166

In your SQL query, you can use TIMESTAMPDIFF to compute the remaining duration:

SELECT TIMESTAMPDIFF(DAY, CURDATE(), DATE(date_submit) + INTERVAL duration DAY) AS remaining

Upvotes: 1

Related Questions