How do I subtract 2 dates/times?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vigour
Forum Newbie
Posts: 18
Joined: Thu Sep 29, 2005 2:04 am

How do I subtract 2 dates/times?

Post by vigour »

I have two dates with times like this:

Start date/time = 2006-01-01 08:12
End date/time = 2006-01-07 10:45

I want to take the End date/time and subtract Start date/time from it.
I want the results in days, hours and minutes.

Like this example:

4 days, 3 hours and 52 minutes.

How do I do that in PHP?
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

strtotime() and then subtract one from the other.
Note that your dates have to be in a standard format.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

viewtopic.php?t=29341 may be of interest.
Post Reply