MySQL sysdate() function; In this tutorial, we would love to share with you how to use sysdate function with example. Also, we will explain sysdate() function definition, syntax and various examples.
The MySQL SYSDATE() function is similar to NOW() but with a small difference.
MySQL SYSDATE() function
Definition:- SYSDATE() function is a built-in MySQL function, which is used to get the current date and time.
Note:-
MySQL sysdate() format :- This function will return date time in the format “YYYY-MM-DD HH:MM:SS” (string) or as YYYYMMDDHHMMSS (numeric).
Syntax
SYSDATE(argument)
argument:- It is an optional parameter. It specifies the fractional seconds precision for the return value.
Example 1 – Basic Usage
Here, we will take an example for demonstrating.
SELECT SYSDATE();
The output of the above query is the following:
+---------------------+ | SYSDATE() | +---------------------+ | 2020-01-04 11:18:09 | +---------------------+
Example 2 – With Fractional Seconds Precision
Here we will take a second example with fractional seconds precision parameters.
SELECT SYSDATE(8);
The output of the above query is the following:
+----------------------------+ | SYSDATE(4) | +----------------------------+ | 2020-01-04 11:19:45.9179 | +----------------------------+
Example 3 – With Numeric Context
Here we will take a third example with a numeric context for demonstration.
SELECT SYSDATE() + 1;
You can also add in mysql sysdate() +1, sysdate() +7, sysdate() +15, sysdate() +30, etc.
The output of the above query is the following:
+----------------------------+ | SYSDATE() + 1 | +----------------------------+ | 20200104112060 | +----------------------------+
MySQL SYSDATE() vs NOW()
- MySQL SYSDATE() returns the time at which it executes.
- MySQL NOW() returns the time at which the statement started executing.