CURDATE () vs NOW() in MySQL


The NOW() function gives current datetime as a timestamp while CURDATE() gives only current date, not time.

Now let us work on both the functions with the help of select statement. The query is as follows −

The following is a demo of NOW() function −

mysql> select NOW();

The following is the output −

+---------------------+
|             now() |
+---------------------+
| 2018-11-27 15:17:01 |
+---------------------+
1 row in set (0.00 sec)

A demo of CURDATE().

mysql> select CURDATE();

The following is the output that displays only date, not time −

+------------+
| curdate() |
+------------+
| 2018-11-27 |
+------------+
1 row in set (0.00 sec)

Now let us understand this with the help of table. Let us create a table −

mysql> create table CurrentdateAndNowDemo
−> (
   −> Time datetime
−> );
Query OK, 0 rows affected (0.82 sec)

Inserting records into table with the help of now() and curdate(). The query is as follows −

mysql> insert into CurrentdateAndNowDemo values(now());
Query OK, 1 row affected (0.11 sec)

mysql> insert into CurrentdateAndNowDemo values(curdate());
Query OK, 1 row affected (0.14 sec)

Now let us check the now() function gives current datetime or not and curdate() gives current date or not. The query is as follows −

mysql> select *from CurrentdateAndNowDemo;

The following is the output that displays the current datetime and current date using now() and curdate() respectively −

+---------------------+
|                Time |
+---------------------+
| 2018-11-27 15:16:32 |
| 2018-11-27 00:00:00 |
+---------------------+
2 rows in set (0.00 sec)

Updated on: 25-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements