there was a question c开发者_开发知识库oming 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
SELECT this, that
FROM here
WHERE start >= NOW()
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.
Sure you can:
WHERE start >= CURDATE()
You can use any expression in the WHERE
clause, using any inbuilt Date-and-Time function.
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.
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();
... WHERE v_date=CURRENT_DATE()
精彩评论