PHPTOM Posted January 9, 2009 Share Posted January 9, 2009 Hi, I am coding a timetable and basically I want to know how to add minutes to 24hour. I have for example 13:00 in the database, and I want to add 120 minutes to this. Can someone assist me in a function to do this please? Thanks Link to comment https://forums.phpfreaks.com/topic/140182-solved-adding-minutes-to-24hour/ Share on other sites More sharing options...
bluesoul Posted January 9, 2009 Share Posted January 9, 2009 $newtime = strtotime("+2 hours",$oldtime); Link to comment https://forums.phpfreaks.com/topic/140182-solved-adding-minutes-to-24hour/#findComment-733569 Share on other sites More sharing options...
PHPTOM Posted January 9, 2009 Author Share Posted January 9, 2009 Sorry doesnt work, it displays 7212. Basically I have: A while, getting the start time from mysql. $starttime = $a['time']; Then I put this $newtime = strtotime("+2 hours",$starttime); and echo $newtime; It displays: 7212 Link to comment https://forums.phpfreaks.com/topic/140182-solved-adding-minutes-to-24hour/#findComment-733576 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 You have to echo it out using [m]date/m] <?php $newtime = strtotime("+2 hours",$a['time']); echo date('H:i', $newtime); ?> Should print it out right. Just remember, we usually provide examples, it is up to you to take those examples and implement them correctly in your code, IE replacing "$oldtime" to be $a['time']. Link to comment https://forums.phpfreaks.com/topic/140182-solved-adding-minutes-to-24hour/#findComment-733580 Share on other sites More sharing options...
PHPTOM Posted January 9, 2009 Author Share Posted January 9, 2009 Yup, I know about examples. I added that variable to show you better, as you won't know what $a['time'] means. I'm having problems with it not working the correct hour out. <table width="100%" cellpadding="4" cellspacing="0" border="0"> <tr> <td><font class="heading2">Start</font></td> <td><font class="heading2">End</font></td> <td><font class="heading2">Presenter</font></td> </tr> <?PHP $q = mysql_query("SELECT * FROM `timetable` WHERE `day` = '".$_GET['day']."' ORDER BY `time` ASC"); while($a = mysql_fetch_array($q)){ $newtime = strtotime("+2 hours", $a['time']); ?> <tr> <td><?=$a['time'];?></td> <td><?=date('H:i', $newtime);?></td> <td><?=$a[presenter];?></td> </tr> <?PHP } ?> </table> This is what I have dispayed: 17:00 02:00 Tom Any ideas? The 02:00 should show 19:00. Link to comment https://forums.phpfreaks.com/topic/140182-solved-adding-minutes-to-24hour/#findComment-733582 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 Ok, I hate that stupid strtotime function, but it should work in this aspect. <?php $newtime = date("H:i", strtotime($a['time'])+3600*2); // 3600*2 = 2 hours ?> That should work I believe. Link to comment https://forums.phpfreaks.com/topic/140182-solved-adding-minutes-to-24hour/#findComment-733584 Share on other sites More sharing options...
PHPTOM Posted January 9, 2009 Author Share Posted January 9, 2009 Edit: Works perfectly. I just plain echod new time, instead of using date. Great thanks a lot! Link to comment https://forums.phpfreaks.com/topic/140182-solved-adding-minutes-to-24hour/#findComment-733594 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 Not sure why, I just ran the test on my server doing this: <?php $a['time'] = "17:00"; $newtime = date("H:i", strtotime($a['time'])+3600*2); // 3600*2 = 2 hours echo "The time should be 19:00 and (drum role) the time is: " . $newtime; die(); ?> Output: The time should be 19:00 and (drum role) the time is: 19:00 Link to comment https://forums.phpfreaks.com/topic/140182-solved-adding-minutes-to-24hour/#findComment-733600 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.