date subtraction php

Hi,

I have a date in the past in format mm/dd/yy hh:mm, like 08/01/14 03:21 or 08/07/14 23:51, i want to substract this from now() and obtain how many hours and minutes are in a format in hh:mm like10:30 or 132:43, any idea?
LVL 1
joyacv2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
Either you have a date typed variable , or you have a string variable that holds a text that can be parsed into a date given that format.
Check out str_to_date function.
0
joyacv2Author Commented:
Hi,

How is that?
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
http://php.net/manual/en/datetime.diff.php
To learn about date time difference function
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

joyacv2Author Commented:
i read that, but don't understand
0
GaryCommented:
What format is that date in ?
Is it dd/mm/yyyy or mm/dd/yyyy
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
0
joyacv2Author Commented:
Hi Gary

 mm/dd/yyyy hh:mm
0
GaryCommented:
<?php
$date1=new DateTime("08/01/14 03:21");

$today = new DateTime(date('Y-m-d h:i'));

$diff = $date1->diff($today);

echo (($diff->format('%d')*24) + $diff->format('%h')) . " hours ";
echo $diff->format('%i minutes');

Open in new window

0
joyacv2Author Commented:
Hi Gary,

But how i acquire a result in a format like hh:mm with the hh without the 23 limitation, like 124:45, sometime like [h]:mm in excel?
0
GaryCommented:
Use the code above, I made an edit
0
GaryCommented:
For that format

echo (($diff->format('%d')*24) + $diff->format('%h')) . ":" . $diff->format('%i');

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
joyacv2Author Commented:
also, this doesn't count in consideration the date, give me only 8 hours
0
joyacv2Author Commented:
works excellent!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.