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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:47:09  来源:igfitidea点击:

Mysql query to get current date from database?

mysqlsql

提问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 NOWfunction:

精美的手册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 CURDATEfunction:

如果您只想要日期,请使用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'