MySQL SYSDATE Function

MySQL SYSDATE is one of the 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 SYSDATE function to find the current date and time with an example. The basic syntax of the SYSDATE Function 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.

Get SYSTEM DATE Example 1

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

SELECT SYSDATE() + 0;

SELECT SYSDATE(), SYSDATE() + 5;

SELECT SYSDATE(), SYSDATE() - 5;
Example 2

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

MySQL SYSDATE function Example 2

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

SELECT SYSDATE(), NOW();

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

SELECT SYSDATE(), SLEEP(2), SYSDATE();
Example 3

Example 3

In this instance, we show how to use this 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 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 customer;
MySQL SYSDATE Function 4