MYSQL NOW() Function Examples

Let’s look at some examples of the NOW function in MySQL. Learning the MySQL NOW function with examples will help you understand the concept better.

Example 1:

In this example, we are finding the current date and time using the NOW function. Here we will get the result in ‘YYYY-MM-DD HH:MM:SS’ format.

Query:

SELECT NOW() 
AS CurrDateTime ;

Output :

CURRDATETIME
2020-11-26 18:37:42

Example 2:

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

SELECT NOW()+ 0 
AS CurrDateTime ;

Output :

CURRDATETIME
20201126183839

Example 3:

In this example, we use the NOW function to set the value of the columns.

First, let’s create a table named DeliveryDetails.

CREATE TABLE Product (
ProductId INT NOT NULL,
ProductName VARCHAR(20) NOT NULL,
Delivered_At TIMESTAMP NOT NULL,
PRIMARY KEY(ProductId)
);

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

INSERT INTO  
Product (ProductId, ProductName, Delivered_At)
VALUES
(1010, 'Apple MacBook', NOW());

Now, check the Product table :

SELECT * FROM Product;

Output :

PRODUCTID PRODUCTNAME DELIVERED_AT
1010 Apple MacBook 2021-10-01 14:41:15

MYSQL NOW() function

MYSQL NOW() function returns the current date and time value.

The date and time returned by the NOW() function in MySQL are 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.

Similar Reads

Syntax

MySQL NOW function syntax is:...

MYSQL NOW() Function Examples

Let’s look at some examples of the NOW function in MySQL. Learning the MySQL NOW function with examples will help you understand the concept better....

Contact Us