Reputation: 161
Database: (gameDay)
id game_Date
1 1996-01-02
I am trying to return the amount of days it has been since this game took place.
The sql query I was trying to run was:
SELECT CURDATE() - gameDay.game_Date AS days
FROM gameDay
WHERE gameDay.id = 1
this was giving me weird number which made no sense:
OR
SELECT DATEDIFF(CURDATE(), gameDay.game_Date) AS days
FROM gameDay
WHERE gameDay.id = 1
This sql query was giving me an error of
Undefined function or expression: CURDATE
OR
SELECT DATEDIFF(DAY, CURDATE(), gameDay.game_Date) AS days FROM gameDay WHERE gameDay.id = 1
and this query gives me this error:
Field is not a valid field based on tables in the query: DAY
Thank you
Upvotes: 0
Views: 4506
Reputation: 4192
IF you use SQL Server database means try below query :
SELECT DATEDIFF(DAY,GETDATE(), gameDay.game_Date) AS days
FROM gameDay
WHERE gameDay.id = 1
IF you use MySQL database means try below query :
SELECT DATEDIFF(`game_Date`, NOW()) AS days
FROM `gameDay`
WHERE `id` = 1
Upvotes: 1