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 |
Similar Reads
SUBDATE() function in MySQL SUBDATE() function in MySQL is used to subtracts a time value (as interval) from a given date. Syntax : SUBDATE(date, INTERVAL expr unit) Parameter : This function accepts three parameters as given below : date : First specified date. expr : The value of the time/date interval to subtract. unit : Th
2 min read
TIME() Function in MySQL The TIME() function in MySQL is used to extract the time portion from a date or datetime expression, returning the time in the format 'HH:MM'. This function is particularly useful when working with time components in databases, such as scheduling or logging systems. In this article, We will learn ab
4 min read
YEAR() Function in MySQL YEAR() function in MySQL is used to find year from the given date. If the date is NULL, the YEAR() function will return NULL. Otherwise, it returns value range from 1000 to 9999. Syntax : YEAR(date) Parameter : This method accepts one parameter as mentioned above and described below : date : The dat
3 min read
SQRT() Function in MySQL The SQRT() function in MySQL calculates the square root of a non-negative number, returning NULL for negative inputs. It is a built-in function that provides high precision and is optimized for performance and making it ideal for mathematical and scientific applications.In the article, we will cover
3 min read
TAN() Function in MySQL TAN() function : This function in MySQL is used to return the tangent of a specified number. In any right triangle, the tangent of an angle is the length of the opposite side divided by the length of the adjacent side. Similarly, this can also be defined as tangent of x is the sine of x divided by t
1 min read