SYSDATE() function in MySQL
Last Updated :
27 Nov, 2020
SYSDATE() function in MySQL is used to return the current date and time in YYYY-MM-DD HH:MM:SS or YYYYMMDDHHMMSS.uuuuuu format depending on the context of the function.
Syntax :
SYSDATE()
Parameter :
This method does not accept any parameter.
Returns :
It returns the current date and time value.
Example-1 :
Getting the current date and time using SYSDATE Function.
SELECT SYSDATE() as CurrentDateAndTime ;
Output :
| CurrentDateAndTime |
| 2020-11-26 01:31:14 |
Example-2 :
Getting the current date and time using SYSDATE Function in numeric format.
SELECT SYSDATE() + 0 as CurrDateAndTime ;
Output :
| CURRDATEANDTIME |
| 20201126013648 |
Example-3 :
The SYSDATE function can be used to set value of columns. To demonstrate create a table named DeliveryDetails.
CREATE TABLE DeliveryDetails (
DeliveryId INT AUTO_INCREMENT,
ProductId INT NOT NULL,
ProductName VARCHAR(20) NOT NULL,
Delivered_At TIMESTAMP NOT NULL,
PRIMARY KEY(DeliveryId)
);
Here, we will use SYSDATE function when a delivery will be completed. The value in Delivered_At column will be the value given by SYSDATE Function.
INSERT INTO
DeliveryDetails(ProductId, ProductName, Delivered_At)
VALUES
(94567, 'Acer Helios', SYSDATE());
Now, checking the DeliveryDetails table :
SELECT * FROM DeliveryDetails;
Output :
| DeliveryId |
ProductId |
ProductName |
Delivered_At |
| 1 |
94567 |
Acer Helios |
2020-11-26 01:40:57 |
Explore
SQL Tutorial
6 min read
Basics
Queries & Operations
SQL Joins & Functions
Data Constraints & Aggregate Functions
Advanced SQL Topics
Database Design & Security