Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
DATE_ADD() Function in MySQL
Next article icon

ADDDATE() function in MySQL

Last Updated : 13 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The ADDDATE() function in MySQL is a powerful tool for adding specific time intervals to date or datetime values. It simplifies data manipulation by allowing us to easily calculate future or adjusted dates based on a given starting point. In this article, we will learn about the ADDDATE() function in MySQL by understanding various examples.

ADDDATE() Function in MySQL

  • The ADDDATE() function in MySQL adds a specified time interval to a date or datetime value.
  • This function can be used in two different formats:

Syntax:

ADDDATE(date, INTERVAL expr unit)

Parameter:

  • date: The starting date or datetime value.
  • expr: The number of time units to add.
  • unit: The unit of time (e.g., DAY, MONTH, YEAR)adds

Returns:

It returns the date or DateTime after adding the interval.

Examples of ADDDATE() Function in MySQL

Example 1:

Let’s Adding 15 days with the specified date using ADDDATE Function.

SELECT ADDDATE('2020-08-20', INTERVAL 15 DAY) 
as Updated_date;

Output:

Updated_date
2020-09-04

Example 2:

Let’s Adding 30 minutes with the specified datetime using ADDDATE Function.

SELECT ADDDATE('2020-08-28 20:59:59', INTERVAL 30 MINUTE) 
as Updated_datetime;

Output:

Updated_datetime
2020-08-28 21:29:59

Example 3:

Let’s Adding 4 weeks with the specified date using ADDDATE Function.

SELECT ADDDATE('2020-08-12', INTERVAL 4 WEEK) 
as Updated_date;

Output:

Updated_date
2020-09-09

Example 4:

Let’s Adding 6 months with the specified date using ADDDATE Function.

SELECT ADDDATE('2019-08-12', INTERVAL 6 MONTH) 
as Updated_date ;

Output:

Updated_date
2020-02-12

Example 5:

Let’s Adding 10 years with the specified date using ADDDATE Function.

SELECT ADDDATE('2010-12-10', INTERVAL 10 YEAR) 
as Updated_date ;

Output:

Updated_date
2020-12-10

Example 6:

Let’s Adding 5 days 10 hour 05 minute  20 seconds with the specified datetime using ADDDATE Function.

SELECT ADDDATE('2020-08-20 05:15:19', INTERVAL '5-10-05-20' DAY_SECOND) 
as Updated_datetime;

Output:

Updated_datetime
2020-08-25 15:20:39

Example 7:

The ADDDATE function can be used to set value of columns. To demonstrate create a table named ScheduleDetails.

CREATE TABLE ScheduleDetails(
TrainId INT NOT NULL,
StationName VARCHAR(20) NOT NULL,
TrainName VARCHAR(20) NOT NULL,
ScheduledlArrivalTime DATETIME NOT NULL,
PRIMARY KEY(TrainId )
);

Now inserting values in ScheduleDetails table. We will use ADDDATE function which will denote delay in arrival timing. The value in ExpectedArrivalTime column will be the value given by ADDDATE Function.

INSERT INTO  
ScheduleDetails (TrainId, StationName, TrainName, ScheduledlArrivalTime )
VALUES
(12859, 'KGP', 'Gitanjali Express ', '2020-11-17 10:20:10');

Now, checking the ScheduleDetails table:

SELECT *, ADDDATE(ScheduledlArrivalTime, INTERVAL '0-5-05-20' DAY_SECOND)  
AS ExpectedArrivalTime FROM ScheduleDetails;

Output:

TRAINID STATIONNAME TRAINNAME SCHEDULEDARRIVALTIME EXPECTEDARRIVALTIME
12859 KGP Gitanjali Express 2020-11-17 10:20:10 2020-11-17 15:25:30

Explanation: This query selects all columns from the `ScheduleDetails` table and uses the `ADDDATE()` function to add a time interval (`0 days, 5 hours, 5 minutes, 20 seconds`) to the `ScheduledlArrivalTime` column. The result is displayed in a new column named `ExpectedArrivalTime`, which shows the adjusted arrival time of the train.

Conclusion

The ADDDATE() function in MySQL provides a versatile solution for handling date and time manipulations. With support for various time units and precise control over date adjustments, it makes tasks like scheduling and tracking time changes much easier. Whether you’re working with simple day additions or complex interval calculations, ADDDATE() is an essential tool for database developers and users.



Next Article
DATE_ADD() Function in MySQL
author
jana_sayantan
Improve
Article Tags :
  • Databases
  • SQL
  • DBMS-SQL
  • mysql

Similar Reads

  • DATE_ADD() Function in MySQL
    DATE_ADD() function in MySQL is used to add a specified time or date interval to a specified date and then return the date. Syntax: DATE_ADD(date, INTERVAL value addunit) Parameter: This function accepts two parameters which are illustrated below: date - Specified date to be modified. value addunit
    2 min read
  • CURDATE() Function in MySQL
    The CURDATE() function in MYSQL is used to return the current date. The date is returned to the format of "YYYY-MM-DD" (string) or as YYYYMMDD (numeric). This function equals the CURRENT_DATE() function. In this article, we are going to discuss about CURDATE() function in detail. Syntax CURDATE(); P
    2 min read
  • DAY() Function in MySQL
    DAY() function : This function in MySQL is used to return the day of the month for a specified date (a number from 1 to 31). This function equals the DAYOFMONTH() function. Syntax : DAY(date) Parameter : This method accepts a parameter which is illustrated below : date : Specified date to extract th
    1 min read
  • DATEDIFF() Function in MySQL
    DATEDIFF() function in MySQL is used to return the number of days between two specified date values. Syntax: DATEDIFF(date1, date2) Parameter: This function accepts two parameters as given below: date1: First specified datedate2: Second specified date Returns : It returns the number of days between
    2 min read
  • UTC_DATE() function in MySQL
    UTC_DATE() function in MySQL is used to check current Coordinated Universal Time (UTC) date. It returns the UTC date value in 'YYYY-MM-DD' or YYYYMMDD format, depending on whether the function is used in string or numeric context. Syntax : UTC_DATE OR UTC_DATE() Parameter : This method does not acce
    2 min read
  • MySQL ADDTIME() function
    MySQL ADDTIME() function adds the specified time intervals to the given date and time. It returns the date or DateTime value after adding the time interval. SyntaxThe MySQL ADDTIME() function syntax is: ADDTIME(expr1, expr2) ParameterADDTIME() function accepts two parameters. expr1: The given dateti
    2 min read
  • DAYNAME() Function in MySQL
    DAYNAME() function : This function in MySQL is used to return the weekday name for a specified date. Syntax : DAYNAME(date) Parameter : This method accepts a parameter which is illustrated below as follows. date - Specified date to extract the weekday name from Returns : It returns the weekday name
    1 min read
  • BIT_AND() function in MySQL
    BIT_AND() : This function in MySQL is used to return the Bitwise AND of all bits in a given expression. It first converts all decimal values into binary values, and then perform bitwise and operation on those binary values. The BIT_AND() function works by performing a bitwise AND operation on each p
    3 min read
  • COT() Function in MySQL
    COT() function : This function in MySQL is used to return the cotangent of a specified number. If the specified number is 0, an error or NULL will be returned. In a right triangle, the cotangent of an angle is the length of it's adjacent side divided by the length of the opposite side. Similarly, th
    1 min read
  • DIV() Function in MySQL
    DIV() function : This function in MySQL is used to return a quotient (integer) value when integer division is done. For example, when 7 is divided by 3, then 2 will be returned. Syntax : SELECT x DIV y; Parameter : This method accepts two parameters as given below as follows. x - Specified dividend
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences