I have two times in PHP and I would like to determine the elapsed hours and minutes. For instance:
8:30 to 10:00 would be 1:30
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A solution might be to use
strtotimeto convert your dates/times to timestamps :And, then, do the difference :
And get the result in minutes or hours :
You’ll get :
What you now have to find out is how to display that 😉
(edit after thinking a bit more)
A possibility to display the difference might be using the date function ; something like this should do :
And I’m getting :
Note that, on my system, I had to use
date_default_timezone_setto set the timezone to UTC — else, I was getting “02:30”, instead of “01:30” — probably because I’m in France, and FR is the locale of my system…