Jump to content

[SOLVED] Strange date behaviour....


CavemanUK

Recommended Posts

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

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";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.