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 today()
 

MySQL today()

Aanchal Sharma
Article byAanchal Sharma
EDUCBA
Reviewed byRavi Rathore

MySQL-today()

Introduction to MySQL today()

In MySQL, the Today() function is a built-in MySQL Date function that provides today’s date value, where we will be using MySQL stored procedures and functions. With this MySQL Today() function, we will learn to create a special type of MySQL stored program by implementing the CREATE FUNCTION query statement.

 

 

In MySQL Today() function, we will build a Date function using some of the MySQL Date functions to access the single Date value, thus called a built-in date utility code. In general, developers use stored functions in MySQL to summarize mutual formulas or implement specific rules that can be reused across multiple SQL statements or stored programs.

Watch our Demo Courses and Videos

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

Syntax

To get MySQL Today() function to result in today’s date, we will use the built-in functions of the date data type. We must create your own MySQL Today() function as a stored program. As we know CURDATE() function or CURRENT_DATE() function in MySQL provides the current date, and we also use it most of the time to retrieve the current date or time in MySQL queries.

Now, we can replace this MySQL CURDATE() function or CURRENT_DATE() function with MySQL Today() function to make the query statements more comprehensible. This is possible by the succeeding SQL command code structure firstly:

DELIMITER $$     // creating stored function program
CREATE FUNCTION FunctionName(
Parameter1,
Parameter2,….
)
RETURNS Data_Type   // Declare the datatype
[NOT] DETERMINISTIC
BEGIN
RETURN  Replaceable_Stored_FunctionName;   // statements
END$$
DELIMITER ;    // end of the procedure

Explaining the terms of the above syntax below:

  • FunctionName specifies the name we give to the stored function when using the CREATE FUNCTION keyword to name and create it.
  • The stored function name followed us; we need to list all the parameters we wanted to mention within the parentheses. All these parameters are the MySQL IN parameters by default, so we cannot state OUT, INOUT, or IN modifiers to those parameters.
  • With the RETURNS statement, we will specify the valid MySQL Data type for which we are creating the stored program function.
  • Then, we must state the DETERMINISTIC keyword to make the function either deterministic or not. In a deterministic function, it also returns the identical result for similar parameters as inputs, whereas, in a non-deterministic one, it outputs different values for similar parameters as inputs. But MySQL uses the NOT DETERMINISTICkeyword option by default if we do not set anyone.
  • Between the BEGIN and END keyword blocks, we can write the code in this body for the stored function. In the body block section, at least a single RETURN query statement should be mentioned, which returns the result value to the calling function. On execution, the stored function terminates instantly if the RETURN query is visited.

After executing the properly stored program syntax above, using valid names for functions, parameters, and data types, the stored function will be created in the MySQL database. We can call the newly built stored program with the following MySQL query and execute the output as desired:

SELECT FunctionName();

The term “FunctionName” is mentioned in the above syntax of the stored program function.

How does MySQL Today() Function work?

Let us consider accessing today’s date by implementing the built-in date functions to provide the current date in the MySQL database.

Sometimes, from the database table rows, we want to fetch data having a date column with the Date data type as today, and then the query will be written as:

SELECT ColumnName FROM TableName WHERE ExpiredDate = Today;

To acquire today’s date, we can use either the CURRENT_DATE() or CURDATE() function with the query as follows:

SELECT CURRENT_DATE() Today;

Output:

MySQL today() - 1

Also, you can use the NOW() function or SYSDATE() function to select the date part from the present date-time resulting by the function as shown follows:

SELECT DATE(SYSDATE()) Today;

Output:

MySQL today() - 2

Now, we can alter the query with the following one:

SELECT ColumnName FROM TableName WHERE ExpiredDate = CURRENT_DATE();

But suppose the column ExpiredDate includes both date and time types; then you can apply DATE() in MySQL to get them just the date value and equate it with the current value of date:

SELECT ColumnName FROM TableName WHERE DATE(ExpiredDate) = CURRENT_DATE();

Examples to Implement Today() function in MySQL

To understand MySQL Today(), we can replace the CURRENT_DATE() function when we use this function many times in the queries.

For this, let us create a stored function named Today() in MySQL with the syntax stated below:

DELIMITER $$
CREATE FUNCTION Today()
RETURNS DATE
BEGIN
RETURN  CURRENT_DATE();
END$$
DELIMITER ;

Execute the above command in the MySQL database, and you will see that the Today() function is created as a stored program. Now, you can call and utilize it in your query statements.

To implement the created program, we will run the following query with the Today() function along with the MySQL SELECT keyword to fetch the current value of the date:

SELECT Today()Today_Date;

Output:

Using Select query - 3

Now, with this MySQL Today() function, a built-in date function with the stored program to output the current date, we can use it to fetch the date of the next day, i.e., tomorrow or more upcoming days. The query can be written as simply as the code below to get tomorrow’s date or the day after tomorrow’s date:

SELECT Today() + interval 2 day Day_after_tomorrow_date;

Output:

MySQL today() - 4

Here, the interval keyword determines the interval value and unit.

Again, let us consider fetching the data which is of either the previous day or, say, yesterday, using the MySQL Today() function as follows:

SELECT Today() -interval 2 day Day_before_yesterday_date;

Output:

Day before yesterday - 5

Conclusion

Likewise, we can also learn and develop the desired function of date or other valid data types in MySQL by applying the stored program and execute it and use it in our MySQL queries. Thus, The MySQL Today() function is a unique stored program we create and query to obtain the current date values. We can use it in MySQL statements to provide the desired output.

Recommended Articles

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

  1. MySQL Timestamp
  2. Working of MySQL Avg()
  3. MySQL MAX() Function
  4. NOT In MySQL

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