I am attempting to write a query that will take a date value and return a numerical value. What I plan to use this for is to track the days until an inspection is due. For example I will input the inspection expiration date into the database, then I want the query to return the value of days remaining until the inspection is due.
Thanks for the help. I am not that good with SQL. I know how to write basic queries but anything past that I really don't know what to do.
Asked
Active
Viewed 39 times
-1

chriss
- 1,528
- 4
- 13
- 18
-
Pick a platform please. MySQL or SQL Server? Read the tag wikis - they are not the same thing. – Aaron Bertrand Oct 19 '14 at 15:19
-
sorry about that I fixed it. – chriss Oct 19 '14 at 15:30
1 Answers
1
You can use timestampdiff()
function to get the remaining days.
Lets say the expire date is 2014-10-31
and comparing with now you can get the days as
mysql> select timestampdiff(day,now(),'2014-10-31') as days ;
+------+
| days |
+------+
| 11 |
+------+
1 row in set (0.00 sec)

Abhik Chakraborty
- 44,654
- 6
- 52
- 63