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:
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() AS 'Todays Date and Time';
SELECT SYSDATE() AS 'Date and Time';
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;
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();
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;