×

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 Triggers

MySQL trigger is a function of the stored procedure to respond to the system program. This function responds and runs any data table event automatically. You can use it for...

5 minutes read.

MySQL Environmental Setup

The MySQL Environmental Setup MySQL is free, open-source, and cross-platform software, which can be downloaded from its official website. MySQL management system installs on Linux, macOS, and windows. MySQL requires a framework...

6 minutes read.

MySQL MIN function

The MIN() function determines the minimum or lowest value of the data set. This function works on numerical data type values. If the table displays zero value, then the row...

4 minutes read.

MySQL POW() function

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

2 minutes read.

MySQL Tutorial

In this tutorial, you will get information about the MySQL management system. This tutorial will cover the basic and advanced level MySQL concepts with examples that will help you become...

5 minutes read.

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 Descending Index

Descending Index It is a type of index that stores key values in descending order. This query improves the performance of an index query. MySQL system displays the index as per...

3 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 RADIANS() function

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

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 FIND_IN_SET() 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 MySQL provides a built-in string function called...

4 minutes read.

MySQL Command line client Basic Queries

MySQL – command line client Basic Queries There are many queries to work with the MySQL command-line client. Today, we will explore MySQL basic queries and their function. The MySQL query...

8 minutes read.

MySQL database queries

MySQL database queries Database queries help to create, use, show and, delete the database. A Database is a collection of several tables and data. The database uses SQL language to perform...

3 minutes read.

MySQL SELF JOIN

This join links table with itself. The inner join, a self join, a right join, and a cross join are connected with two or more two tables. But, the "self...

4 minutes read.

MySQL Features

Features of MySQL MySQL is a relational database management system (RDBMS): It is a collection of many programs and makes relations with many other programs. Easy to use MySQL database: MySQL...

2 minutes read.

MySQL Control flow function

The control flow function uses values or operands for logical operations. These functions can works on single and multiple conditions. The control flow function is based on the Boolean expression....

3 minutes read.

MySQL Stored Procedure

MySQL creates the "stored procedure" function to operate database information. You can use parameters, blocks, and statements to create a new procedure. The procedure requires a database table to use...

3 minutes read.

MySQL LOG2() function

In this context, we will learn how we can use the MySQL LOG2() function to calculate the Logarithm of a specific number with base 2 with proper syntax and examples. Introduction...

2 minutes read.

MySQL ROUND() function

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

3 minutes read.

MySQL LIKE() function

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

4 minutes read.