- 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
MySQL DATE function to return the difference between current date and joining date
At first, find the current date and get the difference between joining date and current date using the DATEDIFF().
The current date is as follows −
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-10-26 | +------------+ 1 row in set (0.00 sec)
Let us first create a table −
mysql> create table DemoTable -> ( -> JoiningDate varchar(40) -> ); Query OK, 0 rows affected (0.61 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('10/10/1998'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('31/12/2010'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('01/01/2017'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('25/10/2019'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output−
+-------------+ | JoiningDate | +-------------+ | 10/10/1998 | | 31/12/2010 | | 01/01/2017 | | 25/10/2019 | +-------------+ 4 rows in set (0.00 sec)
Here is the query to return the difference between current and joining date −
mysql> select datediff(curdate(),str_to_date(JoiningDate,'%d/%m/%Y')) from DemoTable;
This will produce the following output −
+---------------------------------------------------------+ | datediff(curdate(),str_to_date(JoiningDate,'%d/%m/%Y')) | +---------------------------------------------------------+ | 7686 | | 3221 | | 1028 | | 1 | +---------------------------------------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- How to get the difference between date records and the current date in MySQL?
- Find the difference between current date and the date records from a MySQL table
- Select dates between current date and 3 months from the current date in MySQL?
- MySQL query to order and display difference between dates from the current date
- MySQL query to select date >= current date - 3 weeks?
- Get the number of days between current date and date field?
- MySQL date column auto fill with current date?
- MySQL Select Date Equal to Today and return results for the same date?
- How to select a date less than the current date with MySQL?
- 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
- MySQL query to get the current date records wherein one of the columns displays current date
- Calling NOW() function to fetch current date records in MySQL?
- MySQL - Insert current date/time?
- Condition to check for due date and current date records in MySQL where clause

Advertisements