MySQL,SqLite -兼容的时间戳比较


MySQL & SqLite - compatibile timestamp compare

我有php应用程序与测试使用SqLite,但在生产我有MySQL。

我的一些代码在where子句中使用日期比较,但是SqLite不支持NOW()函数。

在MySQL我有:

Select * from `table` where arrive_date < NOW();

其中arrive_date为时间戳类型。

在SqLite中,我应该使用一些代替NOW()的代码,但我不希望其他部分的代码用于测试和生产。

也许这是一种方式来写SQL,使其在两个引擎上工作?

对于SQLite,您可以使用DATETIME()函数

select * from `table` 
where arrive_date < datetime('now');

两种情况都可以使用CURRENT_TIMESTAMP,如

select * from `table` 
where arrive_date < CURRENT_TIMESTAMP;