MySQL Mysql查询从数据库中获取当前日期?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20971893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mysql query to get current date from database?
提问by user2740576
Can anyone please suggest the query to get current date from data base ?
任何人都可以建议查询以从数据库中获取当前日期吗?
回答by ta.speot.is
The fine manualhas this to say about the NOW
function:
精美的手册对NOW
功能有这样的说法:
mysql> SELECT NOW();
-> '2007-12-15 23:50:26'
If you want just the date, then use CURDATE
. The fine manualhas this to say about the CURDATE
function:
如果您只想要日期,请使用CURDATE
. 精美的手册对此CURDATE
功能有以下说明:
mysql> SELECT CURDATE();
-> '2008-06-13'
回答by Imran Ali Khan
MySQL Date Functions The following table lists the most important built-in date functions in MySQL:
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
may be use full
可能会被充分利用
SQL Date Data Types MySQL comes with the following data types for storing a date or a date/time value in the database:
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
Example Query :
示例查询:
SELECT NOW();
Will Return '2007-12-15 23:50:26'