MySQL CURRENT_TIMESTAMP() Function Explained with Examples – MPS


72 / 100

MySQL CURRENT_TIMESTAMP() Function Explained with Examples – MPS

This tutorial explains the best way to use the MySQL CURRENT_TIMESTAMP() operate with the assistance of examples. By utilizing it, you’ll be able to convert or show the present date and time.

The output format is both ‘YYYY-MM-DD HH:MM: SS’ format or YYYYMMDDHHMMSS, which is determined by the context of the calling operate, whether or not it is numeric or string. The operate NOW() and CURRENT_TIMESTAMP() are equal of the CURRENT_TIMESTAMP.

Please notice that examples proven right here will give outcomes relying upon the current date.

current timestamp

MySQL CURRENT_TIMESTAMP()

This operate supplies a date and time worth formatted in a ‘YYYY-MM-DD HH:MM: SS’ model. This operate confirms to work from MySQL variations such as 3.23, 4.0, 4.4, 5.6, 5.7, and so on.

Syntax

It comes in the next varieties:

-- MySQL CURRENT_TIMESTAMP capabilities
CURRENT_TIMESTAMP();
CURRENT_TIMESTAMP(FSP);

The argument, FSP in the second type, represents the fractional seconds precision for the resultant worth. If you need more precision in time worth, then use the 2nd format.

Let’s now undergo among the examples utilizing the MySQL CURRENT_TIMESTAMP() operate.

We suppose that the next subjects would even assist more alongside with this tutorial:

CURRENT_TIMESTAMP() Examples

String context

In this instance, we’re printing the present timestamp worth in the string context.

-- String context
SELECT CURRENT_TIMESTAMP();

The above MySQL assertion would produce the date in customary string format. Check under:

-- Output
'2019-09-05 17:40:20'

Numeric context

Check this instance of utilizing the CURRENT_TIMESTAMP() methodology in a numeric context.

-- Numeric context
SELECT CURRENT_TIMESTAMP() + 0;
SELECT CURRENT_TIMESTAMP() + 1;

The above MySQL statements would produce the date in customary string format. Check under:

-- Output
20190905174020
20190905174021

Fractional Seconds Precision

In this instance, we’re passing FSP worth to set the fractional seconds precision in the consequence.

-- Fractional Seconds Precision
SELECT CURRENT_TIMESTAMP(5);

The output is as follows:

-- Output
'2019-09-05 17:40:54.22207'

Summary – MySQL CURRENT_TIMESTAMP()

We hope it’s best to now really feel comfy in utilizing the MySQL CURRENT_TIMESTAMP() operate. However, you’ll be able to take up more examples and apply.

Also, to be taught SQL from scratch to depth, do learn our step-by-step MySQL tutorial.

Recommended submit:

MySQL CURRENT_TIMESTAMP() Function Explained with Examples – MPS
Source link

Have any Question or Comment?

Leave a Reply

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

Categories

You have successfully subscribed to myprogrammingschool

There was an error while trying to send your request. Please try again.

My Programming School will use the information you provide on this form to be in touch with you and to provide updates and marketing.