×

MySQL NOW() function

In this context, we will learn how we can use the MySQL NOW() function with proper syntax and good examples.

Introduction of MySQL NOW() function

Basically, in MySQL, this function is used to check the current date and time value. The return type for the NOW() function is either in 'YYYY-MM-DD HH:MM: SS' format or YYYYMMDDHHMMSS.uuuuuu format, depending on whether the function is used in a string or numeric context.

Syntax of the MySQL NOW() function

The syntax of the MySQL NOW() function is given as follows:

NOW()

Parameters or arguments used in MySQL NOW() function:

There is no parameter accepted by the NOW() function in MySQL.

Returns:

It will return the current date and time value.

Application used for NOW() function:

The NOW() function can be used in the given below MySQL versions.:

  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1
  • MySQL 4.0
  • MySQL 3.23

Examples of MySQL NOW() function:

Now we will look into some MySQL NOW() function examples and will explore how we can use the NOW function in MySQL.

Example-1 :

Using NOW Function, we will find the current date and time in this example. Here we will get the result in 'YYYY-MM-DD HH:MM: SS' format in MySQL.

SELECT NOW()
as CurrDateTime ;

Output:

CURRDATETIME
2021-10-17 14:37:48
1 row in set (0.00 sec)

Example-2:

In this example, we will get the current date and time using NOW Function in the numeric format in MySQL. Here the result will be in YYYYMMDDHHMMSS.uuuuuu format.

SELECT NOW()+ 0 as CurrDateTime ;

Output:

CURRDATETIME
20211221123839
1 row in set (0.00 sec)

Example-3 :

We can also use The NOW function to set the value of columns. To demonstrate, create a table named Commoditydetails.

CREATE TABLE Commodity (
CommodityId INT NOT NULL,
CommodityName VARCHAR(20) NOT NULL,
Delivered_At TIMESTAMP NOT NULL,
PRIMARY KEY(CommodityId)
);

Here, we will use the NOW function when a delivery is completed. The value in the Delivered_At column will be the value given by NOW Function.

INSERT INTO
Commodity (CommodityId, CommodityName, Delivered_At)
VALUES
(1010, 'Apple MacBook,' NOW());

Now, we will check the Commodity table using the following SELECT statement:

SELECT * FROM Commodity;

Output:

COMMODITYIDCOMMODITYNAMEDELIVERED_AT
1010Apple MacBook2020-10-11 14:41:15

Application of MySQL NOW() function:

This function is used to check the current date and time value.

Summary:

In the above context, we have learned how to use the NOW() function in MySQL to check the current date and time value.


Related Topics

MySQL EQUI JOIN

An equijoin is an operation that combines multiple tables based on equality or matching column values in the associated tables. This operation links more than two tables based on a...

5 minutes read.

MySQL Date and Time function

The date function displays day, year, month, time, and current date. It shows the date and time as per the requirement of the applications. The data either store on the...

8 minutes read.

MySQL RIGHT() Function

In this context, we will learn how we can use the MySQL RIGHT() Function with proper syntax and good examples. Introduction of MySQL RIGHT() function The RIGHT() function in MySQL is used...

3 minutes read.

MySQL DATE_FORMAT() function

In this context, we will learn how we can use the MySQL DATE_FORMAT() function with proper syntax and good examples. Introduction of MySQL DATE_FORMAT() function DATE_FORMAT() function in MySQL is used to...

3 minutes read.

MySQL REVERSE() function

In this context, we will learn how we can use the MySQL REVERSE() function with proper syntax and good examples. Introduction of MySQL REVERSE() function This function could be used to reverse...

2 minutes read.

MySQL ELT() function

In this context, we will learn how we can use the MySQL ELT() function with proper syntax and good examples. Introduction of MySQL ELT() function In the ELT function, the number field...

2 minutes read.

MySQL MOD() function

In this context, we will learn how we can use the MySQL MOD() function with proper syntax and good examples. Introduction of MySQL MOD() function Basically, in MySQL, the MOD() function is...

3 minutes read.

MySQL MAX function

The MAX function is a type of aggregation function that determines the maximum value of the table data. This function works on numerical data type values. If the table displays...

4 minutes read.

MySQL Queries

MySQL Queries MySQL supports SQL queries in the MySQL interface. These queries help to interact data with the application. MySQL uses create database, user database, create a table, truncate table, and...

13 minutes read.

MySQL function

MySQL function is a piece of program to perform some specific task. Here we pass a parameter and then return a single value. MySQL function mainly supports string, numeric, conditional,...

9 minutes read.

MySQL String Function

The string function is used to maintain and operate string values. This function modifies the string data as per function. We can do the concatenation, conversion, removal and replacing the...

4 minutes read.

MySQL Unique index

It helps to maintain data integrity to enforce the uniqueness of values in one or more columns. We can create more than one UNIQUE index in a single table, which...

3 minutes read.

MySQL AVG function

This function works on numerical data type values. The average function shows the average value of the data set. If an average function returns a null value, then the row...

5 minutes read.

MySQL Advance table Query

MySQL Advance table Query The table is created by index, rows, and columns in the MySQL database. The user saves their information in matrix format. The database requires a query to...

14 minutes read.

MySQL FROM_BASE64() function

In this context, we will learn how we can use the MySQL FROM_BASE64()() function with proper syntax and good examples. Introduction of MySQL FROM_BASE64()() function Basically, the FROM_BASE64() function In MySQL decodes...

2 minutes read.

MySQL DELETE JOIN

Sometimes join becomes complicated and unwanted. In such cases, we can delete the unwanted joins in the tables. You can delete inner join, left join, right join as per requirement....

3 minutes read.

MySQL DATE_ADD() function

In this context, we will learn how we can use the MySQL DATE_ADD() function with proper syntax and good examples. Introduction of MySQL DATE_ADD() function In MySQL, the DATE_ADD() function is used...

3 minutes read.

MySQL Invisible Index

Invisible Index MySQL index decides an option to the availability of the index for the query optimizer. This index shows the visible and invisible options to displays the index column in...

3 minutes read.

MySQL HEX() function

In this context, we will learn how we can use the MySQL HEX() function with proper syntax and good examples. Introduction of MySQL HEX() function For returning an equivalent hexadecimal string value...

3 minutes read.

MySQL LOAD_FILE() function

In this context, we will learn how we can use the MySQL LOAD_FILE() function with proper syntax and good examples. Introduction of MySQL LOAD_FILE() function The LOAD_FILE() function in MySQL reads a...

3 minutes read.