MySQL CURRENT TIMESTAMP Function Explained with Examples – MPS

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 to the CURRENT_TIMESTAMP.

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

MySQL CURRENT TIMESTAMP Function
MySQL CURRENT TIMESTAMP Function

MySQL CURRENT TIMESTAMP Function

In this program, we will learn an operation supplies a date and time worth formatted in a ‘YYYY-MM-DD HH:MM: SS’ model. This operation 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 categories:

-- 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 in SQL

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 them.

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

Recommended submit:

Learn More about Salesforce

Pramod Kumar Yadav is from Janakpur Dham, Nepal. He was born on December 23, 1994, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.




Best PYthon Course

Get More trending Courses

Leave a Comment