MySQL SYSDATE() Function with Example

MySQL SYSDATE() Function with Example

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()

  1. MySQL SYSDATE() returns the time at which it executes.
  2. MySQL NOW() returns the time at which the statement started executing.

Recommended Tutorial

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *