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
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.
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
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'
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.
- MySQL Create User with Password Explained with Examples – MPS
- SQL Exercises with Sample Tables and Demo Data – MPS
- MySQL LOWERcase/LCASE() Functions with Simple Examples – MPS
- MySQL Date and Date Functions Explained with Examples – MPS
- MySQL CURRENT_TIMESTAMP() Function Explained with Examples – MPS
- Grant Privileges on a Database in MySQL with Examples – MPs
- MySQL vs PostgreSQL Comparison – Know The Key Differences – MPS
- MySQL UPSERT | Three Techniques to Perform an UPSERT – MPs
Learn More about Salesforce