Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between datetimes in PHP and MySQL

Tags:

php

mysql

I have 2 dates from mysql with datetime format.

Date 1 is:

"2012/09/28 09:28:00" (column name is departure_date)

and Date 2 is:

"2012/09/29 10:48:00" (column name is return_date)

So how to get a result like this: "25 hours 20 minutes"

I don't care about the seconds.

I'm using MySQL and PHP for the programming language.

like image 875
Celia Tan Avatar asked May 03 '26 16:05

Celia Tan


1 Answers

Date difference function already exists

SELECT DATEDIFF('2007-10-04 11:26:00','2007-10-04 11:50:00')

Also you can try TimeDiff

SELECT TIMEDIFF('2007-10-05 12:10:18','2007-10-05 16:14:59') AS duration;

So in your case you have the option to use these two functions like this

SELECT TIMEDIFF(departure_date,return_date) AS duration;
SELECT DATEDIFF(departure_date,return_date) AS duration;
like image 135
Ahmad Avatar answered May 06 '26 04:05

Ahmad