Working out how many hours have pasted from 1 time to anther

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
Darkside
Forum Commoner
Posts: 43
Joined: Wed Oct 30, 2002 4:18 pm

Working out how many hours have pasted from 1 time to anther

Post by Darkside »

I need a way of working out how many hours have pasted from to diffrents times and data. eg

2003-07-05 12:00:00 PM

till

2003-08-05 16:00:00 PM

From those date i can work out that 28 hours have passed but I need to work this out using php. So i either need an easy way to work out the diff of 2 dates or i need 2 be able to break down the dates into Days and hours so I can count them up but i'm really clueless.
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

use mktime to generate UNIX timestamps, subtract and divide by 60..
Darkside
Forum Commoner
Posts: 43
Joined: Wed Oct 30, 2002 4:18 pm

Post by Darkside »

Code: Select all

$time = mktime();
$timediff = ($time - $userї5]) /60;
$hourspass = $timediff / 60;
echo round($hourspass);
I used that i think its working but I need 2 wait an hour! I tired just eaching $timediff and it seems more like minutes then hours so.
thanks alot tho.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

unix timestamps are in seconds since 11/1970 (unix was made shortly after that and figured dates before then don't really need to be cared about)
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

Read the manual on how mktime works, you must convert your stored spacewasting strings to unixtime
Post Reply