SQL查询将NOW()替换为datetime

时间:2015-07-01 06:25:48

标签: sql date timezone utc

我有一个请求:

SELECT 
  *,
  CASE WHEN NOW() BETWEEN `from` AND `to` THEN "1" ELSE "0" END AS status, 
FROM
  `table`
WHERE
  NOW() > `created_at`

我想将NOW()替换为我的$ date变量(UTC)。 我该如何更改我的请求?

P.S我的查询有点改变。

谢谢!

1 个答案:

答案 0 :(得分:2)

如果我们谈论MySQL,我认为我们基于这种语法,这应该有效:

SELECT *
FROM `table`
WHERE  $date > `created_at`

从另一个问题source.

修改

修改

新查询:

SELECT *,
CASE
WHEN $date BETWEEN `from` AND `to` THEN "1" 
ELSE "0" 
END 
AS status, 
FROM `table`
WHERE
$date > `created_at`