从数据库获取当前日期的Mysql查询?

21

请问有人能建议一个从数据库中获取当前日期的查询吗?


23
选择 'www.google.com' 作为答案。 - ta.speot.is
1
http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html - Alex K.
1
http://www.w3schools.com/sql/func_now.asp - Suraj Singh
2个回答

40

精细手册NOW函数有如下描述:

mysql> SELECT NOW();
        -> '2007-12-15 23:50:26'

如果你只需要日期,那么使用CURDATE函数。详细手册CURDATE函数有如下描述:

mysql> SELECT CURDATE();
        -> '2008-06-13'

8

MySQL 日期函数 以下表格列出了 MySQL 中最重要的内置日期函数:

Function       Description
NOW()      Returns the current date and time
CURDATE()      Returns the current date
CURTIME()      Returns the current time
DATE()     Extracts the date part of a date or date/time expression
EXTRACT()      Returns a single part of a date/time
DATE_ADD()     Adds a specified time interval to a date
DATE_SUB()     Subtracts a specified time interval from a date
DATEDIFF()     Returns the number of days between two dates
DATE_FORMAT()  Displays date/time data in different formats

可能会有用

SQL日期数据类型 MySQL在数据库中提供以下数据类型,用于存储日期或日期/时间值:

DATE -       format YYYY-MM-DD
DATETIME -   format: YYYY-MM-DD HH:MM:SS
TIMESTAMP -  format: YYYY-MM-DD HH:MM:SS
YEAR -       format YYYY or YY

示例查询:

SELECT NOW();
        Will Return '2007-12-15 23:50:26'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接