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
    • Python Programs
    • Java Programs
    • SQL FAQ’s

MySQL TIMESTAMP Function

by suresh

MySQL TIMESTAMP function is one of the MySQL Date Functions, which returns the Timestamp from the given date or DateTime. Let us see how to use this MySQL Timestamp function to return the Date and time from the given expression with an example.

MySQL TIMESTAMP Syntax

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

TIMESTAMP(Date or DateTime);

TIMESTAMP(Date or DateTime, Time_expresion);

As you can see from the above syntax, this TIMESTAMP function accepts either one argument or two. If the argument is one, it returns the DateTime. If we provide two agreements, it adds the Time_expression to Date and returns the DateTime. TIMESTAMP(DateTime + Time_expresion)

MySQL TIMESTAMP function Example

The following queries help you understand the use of this Time Stamp function.

Here, we are returning the timestamp of the given Date and DateTime. Within the third statement, we used the second argument. That’s why it adds 10:11:12 time to 06:22:13.

SELECT TIMESTAMP('2019-02-28');

SELECT TIMESTAMP('2019-02-28 14:22:13');

SELECT TIMESTAMP('2019-02-28 06:22:13', '10:11:12');

OUTPUT

MySQL TIMESTAMP Function 1

MySQL TIMESTAMP Function Example 2

In this Date Function example, we are returning the TIMESTAMP from the current date and time returned by the CURDATEfunction, Now function, and UTC_TIMESTAMP function.

SELECT TIMESTAMP(CURDATE()), TIMESTAMP(CURRENT_DATE());

SELECT NOW(), TIMESTAMP(NOW());

SELECT UTC_TIMESTAMP(), TIMESTAMP(UTC_TIMESTAMP());

OUTPUT

MySQL TIMESTAMP Function 2

Here, we are trying to use long hours (2000 hours). It impacts the MySQL Date value as well.

SELECT TIMESTAMP('2019-02-28', '20000:30:20');

SELECT TIMESTAMP(CURDATE(), '20000:30:20');

SELECT TIMESTAMP(NOW(), '700000:30:20');

OUTPUT

MySQL TIMESTAMP Function 3

MySQL TIMESTAMP Example 3

In this example, we show you how to use this Timestamp function on table data. Here, we are adding 10 Hours, 22 Minutes, and 33 Seconds to the HireDate column and retuning the Timestamp.

SELECT EmpID, 
FirstName,
      LastName,
      Occupation,
      YearlyIncome,
      Sales,
      HireDate,
      TIMESTAMP(HireDate, '10:22:33') AS 'TIMESTAMP Example'
FROM `MySQL Tutorial`.customer;

OUTPUT

MySQL TIMESTAMP Function 4

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
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy