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

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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