EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials MySQL Tutorial MySQL CURDATE
 

MySQL CURDATE

Payal Udhani
Article byPayal Udhani
EDUCBA
Reviewed byRavi Rathore

Updated May 24, 2023

MySQL CURDATE

 

 

Introduction to MySQL CURDATE

Manier times while inserting the values in MySQL tables with date columns, we have to insert the date column that is the date at that particular time of insertion, or even set the default value of the date column to the date on which that record is inserted. In all such cases, we need to retrieve the value of the date at that particular instance when the operation is being performed. For this, Mysql has provided the functionality to use the CURDATE function to retrieve the current date.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

In this article, we will learn how to use the CURDATE function, its syntax and example, alternatives of the CURDATE function in MySQL, and the difference between the NOW() functionality and the CURDATE() functionality.

Syntax

string/number CURDATE();

Explanation: The CURDATE() function returns the value of the current date or the date at that particular instance when the function is being called. The date format depends upon the context in which the function is being called. For example, when string context is used, the retrieved data’s format is in the ‘YYYY-MM-DD’ format. At the same time, in the case of numeric context, the format of the fetched date changes to YYYY-MM-DD format.

How does MySQL CURDATE work?

Let us retrieve the value of the CURDATE() function using the simple SELECT statement as follows:

Code:

SELECT CURDATE();

Output:

mysql curdate1

Explanation: that is the date when the article is being written in the ‘YYYY-MM-DD’ format. As we can see, the default format used is the ‘YYYY-MM-DD’, and the return type is a string. Let us convert the retrieved value in the numeric context value by adding 0 or 1 value or some other number to convert the returned value implicitly to the numeric value. We will use the following query statements.

Code:

SELECT 0 + CURDATE();

Output:

mysql curdate2

Explanation: Execution of the above query statement gives the following output with today’s date value in YYYY-MM-DD format.

Code:

SELECT 1 + CURDATE();

Output:

mysql curdate3

Explanation: Execution of the above query statement gives the following output with tomorrow’s date value as it is equivalent to today’s date plus one day in YYYY-MM-DD format.

Examples to Implement MySQL CURDATE

Below are some examples mentioned:

Example #1

Let us see how we can use it in the table to insert the date column to today’s date. We will create a table named educba_writers with a joining_date column with date data type with the help of the following query statement:

Code:

CREATE TABLE 'educba_writers' (
'id' int(11) NOT NULL,
'firstName' varchar(10) COLLATE latin1_danish_ci NOT NULL,
'rate' decimal(5,2) DEFAULT NULL,
'joining_date' date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_danish_ci;

Output:

mysql curdate4

Example #2

We will insert the values in the educba_writers table with today’s date as the joining_date value using the CURDATE function. For this, we will use the following insert query statement. Let us insert some more rows with non-null rate and joining date value:

Code:

INSERT INTO 'educba_writers' ('id', 'firstName', 'rate', 'joining_date') VALUES
(1, 'Payal', 750, CURDATE());

Output:

mysql curdate5

Example #3

Let us retrieve the record and view the inserted value in the educba_writers table using the following query statement:

Code:

SELECT * FROM educba_writers;

Output:

retrieve the record

Example #4

We can see that the value of today’s date, 2020-05-27, in the ‘YYYY-MM-DD’ format is inserted in the joining_date column. We can even insert the dates concerning today’s date using the CURDATE() function. Like for example, we can add the joining date as two days prior or three days later than today by reducing that many days from the CURDATE() function. Suppose we have to insert a writer record named Vyankatesh, whose joining was two days prior to today. Then we can make use of the following query statement to insert this record:

Code:

INSERT INTO 'educba_writers' ('id', 'firstName', 'rate', 'joining_date') VALUES
(2, 'Vyankatesh', 700, CURDATE()-2);

Output:

add joining date

Example #5

Let us retrieve the record and view the inserted value in the educba_writers table using the following query statement:

Code:

SELECT * FROM educba_writers;

Output:

educba_writers table

Example #6

Suppose we have to insert a writer record named Omprakash, whose joining is after four days. Then we can use the query statement as follows:

Code:

INSERT INTO 'educba_writers' ('id', 'firstName', 'rate', 'joining_date') VALUES
(3, 'Omprakash', 600, DATE_FORMAT((CURDATE() + 4), "%Y-%m-%d"));

Output:

record

Example #7

Let us retrieve the record and view the inserted value in the educba_writers table using the following query statement:

Code:

SELECT * FROM educba_writers;

Output:

view the inserted value

Alternatives of CURDATE() function

We can use the CURRENT_DATE and CURRENT_DATE() functions instead of the CURDATE() function, as both of them work in the same way and return the same value as that of the CURDATE() function. Let us confirm the working of all three functions by executing a simple query of SELECT that will retrieve the value of all three functionalities as follows:

Code:

SELECT CURDATE(), CURRENT_DATE, CURRENT_DATE();

Output:

Alternatives

Explanation: We can see that all three functions and statements retrieved the same value on 2020-05-27, which is today’s date.

Difference between NOW() function and CURDATE()

Now() function retrieves the whole timestamp that includes the current date and time, while the CURDATE() function retrieves only the current date. The date part of the NOW() function is equivalent to the CURDATE() function’s output. Let us see the result by using the following query statement:

Code:

SELECT CURDATE(), DATE(NOW()), NOW();

Output:

Difference

Explanation: We can observe that the value of the CURDATE() and DATE(NOW()) expressions is equivalent.

Conclusion

We can use MySQL’s CURDATE() function to retrieve the current date and manipulate it according to our necessity.

Recommended Articles

We hope that this EDUCBA information on “MySQL CURDATE” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. SQL Data Types
  2. SQL Date Function
  3. MySQL BIN()
  4. MySQL INSTR()

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW