简体   繁体   中英

SQL SELECT NOW()

Hey ya'll sorry for all the caps in the title, but its actually suppose to be like that.

I am running this in query

SELECT NOW()

and it returns this

2012-05-14 17:35:37

how do I remove the time, I only want the date.

How about CURDATE() ?

SELECT CURDATE()

(Note: this is listed as MySQL in the webpage. Unsure what vendor/version of SQL you're running.)

This MySQL select should return the date without the time.

SELECT CURRENT_DATE();

enjoy :)

我认为这也可行

SELECT CONVERT(VARCHAR(10),GETDATE(),111)

You could use the LEFT() function:

SELECT LEFT(NOW(), 10);

Here's a little demo:

mysql> SELECT LEFT(NOW(), 10);
+-----------------+
| LEFT(NOW(), 10) |
+-----------------+
| 2012-05-14      |
+-----------------+
1 row in set (0.00 sec)

这样就像perdfect一样对我说:

SELECT * FROM table WHERE DATE(myDate) = DATE(NOW())
DATE(NOW())

是我使用的 - 它只保留日期部分

You can also create a date format and use NOW() .

| date_int | date         | YES  |     | NULL    |       |
+----------+--------------+------+-----+---------+-------+
mysql> UPDATE borderaux SET date_int = NOW();

+------------+
| date_int   |
+------------+
| 2013-07-15 |
+------------+

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM