
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- What is the difference between MySQL NOW() and CURDATE() function?
- How can I use INTERVAL keyword with MySQL NOW() and CURDATE() functions?
- How to make MySQL's NOW() and CURDATE() functions use UTC?
- Change the curdate() (current date) format in MySQL
- How to use CONTAINS() with CURDATE in MySQL?
- How to get the previous day with MySQL CURDATE()?
- MySQL's now() +1 day?
- WHERE vs HAVING in MySQL?
- length() vs char_length() in MySQL?
- How MySQL behaves when we use INTERVAL of time unit with CURDATE() function?
- Select records from MySQL NOW() -1 Day?
- MySQL ON vs USING?
- Calling NOW() function to fetch current date records in MySQL?
- How to apply NOW() to timestamps field in MySQL Workbench?
- MySQL DateTime Now()+5 days/hours/minutes/seconds?
