Convert TIMEDIFF to hours plus minutes

time1: 2013-08-26 16:33:00 time2: 2013-08-26 15:10:00 $query="UPDATE `FlightSchedule` SET delay = MINUTE(TIMEDIFF(time1, time2)) WHERE `flightNum_arr`='".$flightNum_arr."';"; 

Saves the value 23 as a delay. Instead, the correct answer should be 83 minutes. How to get it?

+4
source share
2 answers

I think you are looking for:

 $query="UPDATE `FlightSchedule` SET delay = CEIL((UNIX_TIMESTAMP(time1) - UNIX_TIMESTAMP(time2))/60) WHERE `flightNum_arr`='".$flightNum_arr."';"; 

As an alternative, there is a TIME_TO_SEC function - and since it gives a result in seconds, you also need to divide it by 60.

+4
source

It returns 1 hour 23 min . You should get an hour.

The following codes return 4980 seconds. And you have to split 60 minutes.

You can use TIME_TO_SEC

 TIME_TO_SEC(TIMEDIFF(time1, time2)) / 60 
+4
source

Source: https://habr.com/ru/post/1498967/


All Articles