Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

MySQL TIMESTAMPADD Function

by suresh

MySQL TIMESTAMPADD function is one of the MySQL Date Functions, used to add the user-specified intervals to a given date or DateTime. Let us see how to use this MySQL TIMESTAMP ADD function to add intervals to a given date expression with an example.

MySQL TIMESTAMPADD Syntax

The basic syntax of the TIMESTAMPADD() Function in MySQL is as shown below:

TIMESTAMPADD(Unit, INTERVAL_expression, DateTime_expression);
  • DateTime: Accepts either DateTime value or date.
  • INTERVAL_Expression: You have to specify the Value that you want to add to the TIMESTAMP.
  • Unit: Accepts values from Microsecond to Year

MySQL TIMESTAMPADD function Example 1

The below shown queries help you understand the use of this MySQL TIMESTAMP ADD function. Here, First, we are adding 111222 Microseconds to 2019-01-31 date. Next, we added 30 Seconds to date. Within the third statement, we added 25 Minutes to the given Date (2019-01-31).

SELECT TIMESTAMPADD(MICROSECOND, 111222, '2019-01-31');

SELECT TIMESTAMPADD(SECOND, 59, '2019-01-31');

SELECT TIMESTAMPADD(MINUTE, 25, '2019-01-31');
MySQL TIMESTAMPADD Function 1

TIP: I suggest you refer to the Date Function article in MySQL to understand the Units after the Interval.

MySQL TIMESTAMPADD Function Example 2

In this example, First, we are adding 48 Hours. Next, we added 48 weeks to a given Date expression. Within the third statement of MySQL TIMESTAMPADD function, we added 14 Years.

SELECT TIMESTAMPADD(HOUR, 48, '2019-01-31');

SELECT TIMESTAMPADD(WEEK, 48, '2019-01-31');

SELECT TIMESTAMPADD(YEAR, 14, '2019-01-31');
 MySQL TIMESTAMPADD Function 2

MySQL TIMESTAMPADD Example 3

In this example, we show you how to use this MySQL Timestamp add function on a table data. Here, we are adding 100 Hours to the HireDate column and retuning the Timestamp.

SELECT EmpID, 
FirstName,
      LastName,
      Occupation,
      YearlyIncome,
      Sales,
      HireDate,
      TIMESTAMPADD(HOUR, 100, HireDate) AS 'TIMESTAMPADD Example'
FROM `MySQL Tutorial`.customer;
MySQL TIMESTAMPADD Function 3

Placed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy