数据库:(gameDay)
id game_Date
1 1996-01-02
我正在尝试归还自这场比赛发生以来的日子。
我尝试运行的SQL查询是:
SELECT CURDATE() - gameDay.game_Date AS days
FROM gameDay
WHERE gameDay.id = 1
这给了我奇怪的数字,没有任何意义:
要么
SELECT DATEDIFF(CURDATE(), gameDay.game_Date) AS days
FROM gameDay
WHERE gameDay.id = 1
这个SQL查询给我一个错误
未定义的函数或表达式:CURDATE
要么
SELECT DATEDIFF(DAY,CURDATE(),gameDay.game_Date)AS天
从gameDay
WHERE gameDay.id = 1
这个查询给我这个错误:
字段不是基于查询中的表的有效字段:DAY
谢谢
最佳答案
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