CavemanUK Posted May 21, 2008 Share Posted May 21, 2008 Hi, Im relatively new to PHP and its completely possible im doing something wrong but can someone explain the following... i have the following piece of code... $minutes=30; $hours=6; for ($increment=0; $increment <= 1030; $increment+=30) { $caltime = date("H:i",mktime($hours,$minutes+$increment,0, 0, 0, 0)); echo $caltime; } my goal is to print times from 06:00 to 23:30 in steps of 30 minutes. As you can guess, its for a calendar... so i want to output.. 06:00 06:30 07:00 .. and so on.... Im using MAMP for OSX as a test server and it works great... but when i upload the code to my host, it shows.. 00:59 00:59 00:59 anyone have any idea why? thanks in advance... CavemanUK Link to comment https://forums.phpfreaks.com/topic/106636-solved-strange-date-behaviour/ Share on other sites More sharing options...
soycharliente Posted May 21, 2008 Share Posted May 21, 2008 This works for me! <?php $minutes = 30; $hours = 6; for ($increment=0; $increment <= 1030; $increment += 30) { $caltime = date("H:i", mktime($hours, $minutes+$increment, 0, date("m"), date("d"), date("Y"))); echo "{$caltime}<br />\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/106636-solved-strange-date-behaviour/#findComment-546574 Share on other sites More sharing options...
CavemanUK Posted May 21, 2008 Author Share Posted May 21, 2008 Hi Charlie, Thanks, that worked great.. i didnt realise i had to specify day, month, year even when not using them. Once again, thanks very much.. CavemanUK Link to comment https://forums.phpfreaks.com/topic/106636-solved-strange-date-behaviour/#findComment-546588 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.