Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

NOW() function in MYSQL

  • Last Updated : 11 Jan, 2021

NOW() :
This function in MySQL is used to check the current date and time value. The return type for 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 :

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

NOW()

Parameter :
This method does not accept any parameter.

Returns :
It returns the current date and time value.



Example-1 :
Finding the current date and time using NOW Function. Here we will get the result in ‘YYYY-MM-DD HH:MM:SS’ format.

SELECT NOW() 
as CurrDateTime ;

Output :

CURRDATETIME
2020-11-26 18:37:42

Example-2 :
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 :
We can also use The NOW function to set value of columns. To demonstrate 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 NOW function when a delivery will be completed. The value in Delivered_At column will be the value given by NOW Function.

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

Now, checking the Product table :

SELECT * FROM Product;

Output :

PRODUCTIDPRODUCTNAMEDELIVERED_AT
1010Apple MacBook2021-10-01 14:41:15
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!