Home > Database > Mysql Tutorial > Code example of curdate() function in MySQL

Code example of curdate() function in MySQL

黄舟
Release: 2017-09-11 11:19:13
Original
2333 people have browsed it

This article mainly introduces the relevant information about the detailed explanation of the MySQL curdate() function. I hope this article can help everyone understand how to use MysqL curdate(). Friends in need can refer to it

MySQL CURDATE function introduction

If you use the string context or YYYMMDD format in a numeric context, the CURDATE() function will return the current date as a value in the "YYYY-MM-DD" format.

The following example shows how to use the CURDATE() function in a string context.


sql> SELECT CURDATE();
+------------+
| CURDATE() |
+------------+
| 2017-08-10 |
+------------+
1 row in set (0.00 sec)
Copy after login

The following examples illustrate how the CURDATE() function can be used in a numeric context:


##

mysql> SELECT CURDATE() + 0;
+---------------+
| CURDATE() + 0 |
+---------------+
|   20170810 |
+---------------+
1 row in set
Copy after login

CURRENT_DATE and CURRENT_DATE( ) is a synonym for CURDATE().


mysql> SELECT CURRENT_DATE(), CURRENT_DATE, CURDATE();
+----------------+--------------+------------+
| CURRENT_DATE() | CURRENT_DATE | CURDATE() |
+----------------+--------------+------------+
| 2017-08-10   | 2017-08-10  | 2017-08-10 |
+----------------+--------------+------------+
1 row in set
Copy after login

CURDATE and NOW functions

The CURDATE() function only returns the current date, while the NOW() function returns the current time Date and time part. The result of the CURDATE() function is equivalent to the following expression:


 mysql> SELECT DATE(NOW());
+-------------+
| DATE(NOW()) |
+-------------+
| 2017-08-10 |
+-------------+
1 row in set
Copy after login
In this tutorial, you learned how to use the MySQL CURDATE() function to get the current date value.

The above is the detailed content of Code example of curdate() function in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template