How to Calculate the Difference Between Two Dates in MySQL Database: MySQL Operators: DATEDIFF Table of Contents Problem: Example: Solution: Discussion: Problem: You have two columns of the date type and you want to calculate the difference between them. Example: In the travel table, there are three columns: id, departure, and arrival. You'd like to calculate the difference between arrival and departure, or the number of days from arrival to departure inclusively. The travel table looks like this: iddeparturearrival 12018-03-252018-04-05 22019-09-122019-09-23 32018-07-142018-07-14 42018-01-052018-01-08 Solution: SELECT id, departure, arrival, DATEDIFF(arrival, departure) AS date_difference, DATEDIFF(arrival, departure) + 1 AS days_inclusive FROM travel; The result is: iddeparturearrivaldate_differencedays_inclusive 12018-03-252018-04-051112 22019-09-122019-09-231112 32018-07-142018-07-1401 42018-01-052018-01-0834 Discussion: To count the difference between dates in MySQL, use the DATEDIFF(enddate, startdate) function. The difference between startdate and enddate is expressed in days. In this case, the enddate is arrival and the startdate is departure. In most cases, though, what you really want is the number of days from the first date to the second date inclusively. You need to add 1 day to the difference: DATEDIFF(arrival, departure) + 1. Recommended courses: SQL Basics in MySQL Common MySQL Functions SQL Practice Set in MySQL Data Types in SQL Recommended articles: MySQL Cheat Sheet How to Analyze a Time Series in SQL Performing Calculations on Date- and Time-Related Values MySQL Date Functions: Complete Analyst’s Guide See also: How to Add Days to a Date in MySQL How to Add Time to a Datetime Value in MySQL How to Get the Year from a Datetime Column in MySQL How to Find the Number of Days Between Two Dates in MySQL Subscribe to our newsletter Join our monthly newsletter to be notified about the latest posts. Email address How Do You Write a SELECT Statement in SQL? What Is a Foreign Key in SQL? Enumerate and Explain All the Basic Elements of an SQL Query