- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the difference between date records and the current date in MySQL?
Let’s say the current date is 2019-09-06. For our example, we will first create a table −
mysql> create table DemoTable ( AdmissionDate date ); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-01-08'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('2018-09-06'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2016-10-26'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------+ | AdmissionDate | +---------------+ | 2019-01-08 | | 2018-09-06 | | 2016-10-26 | +---------------+ 3 rows in set (0.00 sec)
Following is the query to get the difference between date records and current date;
mysql> select datediff(now(),AdmissionDate) from DemoTable;
This will produce the following output −
+-------------------------------+ | datediff(now(),AdmissionDate) | +-------------------------------+ | 241 | | 365 | | 1045 | +-------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Find the difference between current date and the date records from a MySQL table
- MySQL DATE function to return the difference between current date and joining date
- MySQL query to get the current date records wherein one of the columns displays current date
- MySQL query to find the date records wherein the current date and time is in between the JoiningDate and RelievingDate
- Comparison of varchar date records from the current date in MySQL
- How to get the records of the last two days from the current date in MySQL?
- Get the number of days between current date and date field?
- Select dates between current date and 3 months from the current date in MySQL?
- Condition to check for due date and current date records in MySQL where clause
- MySQL query to order and display difference between dates from the current date
- Display all records ignoring the current date record in MySQL
- MySQL query to get current datetime and only current date
- How to compare the first date and the last date from a MySQL column with date records?
- Select a column if condition is met in MySQL to fetch records from current date and current date + 1
- How to get the current date in Java?

Advertisements