问题:如何在where子句中使用当前时间

发布于 2024-09-13 00:10:20 字数 258 浏览 3 评论 0原文

我想到了一个问题。是否有可能使用当前时间戳而不是Where子句中的选定日期?


SELECT this, that
FROM here
WHERE start>='2010-07-01'

我以为这会是……。例如:start='now()' 或 curdate() 或 curtime()。 我发现它们在 Select 子句中使用,但我在Where 中需要它。

非常感谢任何帮助。 弗洛拉

there was a question coming up to my mind. Is there any possibility to use the current timestamp instead of a selected date in the Where Clause?


SELECT this, that
FROM here
WHERE start>='2010-07-01'

I thought it would be sth. like: start='now()' or curdate() or curtime().
Anything I found was that they're used in the Select Clause, but I need it in Where.

Any help is much appreciated.
Flora

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

从﹋此江山别 2024-09-20 00:10:20
SELECT this, that
FROM here
WHERE start >= NOW()
SELECT this, that
FROM here
WHERE start >= NOW()
末骤雨初歇 2024-09-20 00:10:20

您可以根据您的要求使用以下三个函数中的任何一个:

SELECT NOW(),CURDATE(),CURTIME()

此查询的输出是 -

NOW()                | CURDATE()    | CURTIME()
---------------------+----------------+----------
2008-11-11 12:45:34  | 2008-11-11   | 12:45:34

已编辑:
您可以按照指示在Where子句中使用这些函数。

You can use any of the following three functions as per your requirements:

SELECT NOW(),CURDATE(),CURTIME()

The output of this query is -

NOW()                | CURDATE()    | CURTIME()
---------------------+----------------+----------
2008-11-11 12:45:34  | 2008-11-11   | 12:45:34

Edited:
you can use these functions in Where clause as instructed.

情深如许 2024-09-20 00:10:20
... WHERE v_date=CURRENT_DATE()
... WHERE v_date=CURRENT_DATE()
找个人就嫁了吧 2024-09-20 00:10:20

当然可以:

WHERE start >= CURDATE()

您可以在 WHERE 子句中使用任何表达式,使用任何 内置日期和时间函数

Sure you can:

WHERE start >= CURDATE()

You can use any expression in the WHERE clause, using any inbuilt Date-and-Time function.

半岛未凉 2024-09-20 00:10:20

我会使用

WHERE start >= current_timestamp

Just 因为这应该适用于每个 DBMS。但不知道 NOW() ,也许这是一个标准函数?

更新:现在我知道 NOW() 至少在 Oracle 中不起作用,所以我肯定会使用 current_timestamp、current_date 等,因为这些是标准中的。我已经完成了几次 DBMS 迁移(DB2 -> MySQL、MySQL -> Oracle 等),我很高兴我们尽可能使用符合标准的 SQL,这使得迁移相对轻松。

I'd use

WHERE start >= current_timestamp

Just because this should work in every DBMS. Don't know about NOW() though, maybe that's a standard function?

Update: well now I know NOW() does not work at least in Oracle, so I'd definitely go with current_timestamp, current_date etc, because these are in the standard. I've done a couple of DBMS migrations (DB2 -> MySQL, MySQL -> Oracle etc) and I'm glad we used the standards -compliant SQL where ever possible, which made the migrations relatively painless.

薆情海 2024-09-20 00:10:20

您不应该引用函数名称

使用如下所示的函数名称:

  • SELECT this, that FROM here WHERE
    start >= NOW();

  • 从这里选择这个,那个
    start >= CURRENT_DATE();

You shouldn't to quote a function name

Use function names like this:

  • SELECT this, that FROM here WHERE
    start >= NOW();

  • SELECT this, that FROM here WHERE
    start >= CURRENT_DATE();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文