MySQL SYSDATE Function

MySQL SYSDATE function is one of the MySQL Date Functions, which returns the current system Date and Time in YYYY-MM-DD HH:MM:SS or YYYYMMDDHHMMSS.uuuu format.

In this article, we show how to use this MySQL SYSDATE function to find the current date and time with an example. The basic syntax of the SYSDATE() Function in MySQL is as shown below:

SYSDATE();

MySQL SYSDATE function Example

The below-shown query shows you the basic use of this SYSDATE function to return or find the current date and time.

SELECT SYSDATE();

SELECT SYSDATE() AS 'Todays Date and Time';

SELECT SYSDATE() AS 'Date and Time';

As you can see from the screenshot below, it returns the current system date and Time in YYYY-MM-DD HH:MM:SS format. Within the last two MySQL statements, we used the Alias Names.

MySQL SYSDATE Function 1

The following query shows you what happens when we add or subtract value to this SYSDATE function output.

SELECT SYSDATE() + 0;

SELECT SYSDATE(), SYSDATE() + 5;

SELECT SYSDATE(), SYSDATE() - 5;
MySQL SYSDATE Function 2

As you can see from the above screenshot, it added and subtracted those values to the current system date and time. Next, it was displayed the DateTime in YYYYMMDDHHMMSS string format

MySQL SYSDATE function Example 2

In most cases, the NOW and SYSTEM functions return the same output. They differ in the execution time. I mean, SYSDATE Date Function returns the value when executes, NOW returns the constant time. Let us see one example.

SELECT SYSDATE(), NOW();

SELECT NOW(), SLEEP(2), NOW();

SELECT SYSDATE(), SLEEP(2), SYSDATE();
MySQL SYSDATE Function 3

MySQL SYSDATE Example 3

In this instance, we show how to use this SYSDATE function on table data. Here, we are using a datediff function to find the difference between the current system DateTime and the Hire Date column value.

For this MySQL SYSDATE demonstration, we are using Workbench to write a query against the customer database.

SELECT EmpID,
FirstName,
LastName,
Occupation,
YearlyIncome,
Sales,
HireDate,
DATEDIFF(SYSDATE(), HireDate) AS Difference
FROM `MySQL Tutorial`.customer;
MySQL SYSDATE Function 4