2014-01-07 84 views
13

任何人都可以请建议查询从数据库中获取当前日期吗?Mysql查询从数据库中获取当前日期?

+20

'SELECT 'www.google.com' AS answer' –

+1

http://dev.mysql.com/doc/refman/5.7/en/date-and- time-functions.html –

+1

http://www.w3schools.com/sql/func_now.asp –

回答

28

The fine manual有这样说的NOW功能:

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

如果你只想要日期,然后使用CURDATEThe fine manual有这样说的CURDATE功能:

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

的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' 
相关问题