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
froth
Forum Commoner
Posts: 31 Joined: Sat Jan 22, 2005 9:26 pm
Post
by froth » Sun Jan 23, 2005 6:00 pm
I have 10 variables:
The minute of time #1
The hour of time #1
The day of time #1
The month of time #1
The year of time #1
The minute of time #2
The hour of time #2
The day of time #2
The month of time #2
The year of time #2
And I need to find the exact time in
minutes between those two times. I don't need anything but the minutes, but the other numbers must be taken into consideration (like if one time is 23:55 and the other is 0:15, day has to be considered). Does anybody have a prewritten function that can do this? I've been working on this for awhile and don't want to have to write it again.
Thanks much in advance
The Monkey
Forum Contributor
Posts: 168 Joined: Tue Mar 09, 2004 9:05 am
Location: Arkansas, USA
Post
by The Monkey » Sun Jan 23, 2005 6:26 pm
I highly recommend using Unix Timestamps via the PHP
time() and
date functions.
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Sun Jan 23, 2005 7:13 pm
last time i demonstrate the power of
http://www.php.net/strtotime on this forum
Code: Select all
$t1 = strtotime("$year1-$month1-$day1 $hour1:$minute1:$second1");
$t2 = strtotime("$year2-$month2-$day2 $hour2:$minute2:$second2");
$diff = $t1 - $t2;
froth
Forum Commoner
Posts: 31 Joined: Sat Jan 22, 2005 9:26 pm
Post
by froth » Sun Jan 23, 2005 7:18 pm
So how do you extract the # of minutes out of diff?
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Sun Jan 23, 2005 7:34 pm
rule of 3 :p
(1) 60 * second = 1 * minute
=>
(2) 1 * seconds = 1 / 60 minute
=>
(3) x * seconds = x / 60 minute
froth
Forum Commoner
Posts: 31 Joined: Sat Jan 22, 2005 9:26 pm
Post
by froth » Sun Jan 23, 2005 7:41 pm
oh so diff is just the # of seconds. I can do that.
btw congrats on your thousanth post.
Last edited by
froth on Sun Jan 23, 2005 7:49 pm, edited 2 times in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jan 23, 2005 7:45 pm
ooo... I didn't even notice that.. yay tim.
froth
Forum Commoner
Posts: 31 Joined: Sat Jan 22, 2005 9:26 pm
Post
by froth » Sun Jan 23, 2005 7:49 pm
also, does that code work on a 24-hour clock?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jan 23, 2005 8:10 pm
it doesn't care about time of day, week, year, century (for the most part)
froth
Forum Commoner
Posts: 31 Joined: Sat Jan 22, 2005 9:26 pm
Post
by froth » Sun Jan 23, 2005 8:54 pm
Code: Select all
$t1 = strtotime("$begyr-$begmnth-$begdy $beghr:$begminte:0");
$t2 = strtotime("$yr-$mnth-$dy $ahour:$aminute:0");
$diff = ($t1 - $t2) / 60;
diff should be the # of minutes, right?
it doesn't work. for times ~30 minutes apart, diff is 782.
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Sun Jan 23, 2005 10:22 pm
echo out the strings you call strtotime with.....
because overhere everythings works as it should...
Code: Select all
$t1 = strtotime('2005-01-24 23:55:00');
$t2 = strtotime('2005-01-25 00:15:00');
$diff = ($t2 - $t1) / 60;
echo $diff;
only 6000 post or more to get at feyd's level