jpratt Posted May 17, 2008 Share Posted May 17, 2008 I have two timestamps comming in from a mysql database. For my testing Im using the following stamps: 2007-12-17 15:30:00 2007-12-17 17:00:00 My page needs to display a select box with the values between the stamps every half an hour. so in this instance it should loop and display the following values in the box: 3:30 pm 4:00 pm 4:30 pm I have played with the following without luck: while ($stime != $etime) { echo "<option value='" . $stime . "'>" . date("g:i a", strtotime($stime)) . "</option>"; $stime = date("i", strtotime($stime)) + 30; } The ideo is to loop through until the start and end stamps match. Any idea on how to do this? Link to comment https://forums.phpfreaks.com/topic/106112-time-subtraction/ Share on other sites More sharing options...
Barand Posted May 18, 2008 Share Posted May 18, 2008 try <?php $d1 = '2007-12-17 15:30:00'; $d2 = '2007-12-17 17:00:00'; $t1 = strtotime($d1); $t2 = strtotime($d2); while ($t1 < $t2) { echo date ('g:i a', $t1), '<br/>'; $t1 = strtotime('+30 minutes', $t1); } ?> Link to comment https://forums.phpfreaks.com/topic/106112-time-subtraction/#findComment-543864 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.