Jump to content

Array question


beachdaze

Recommended Posts

n00bie here - Need to have an array that returns time in 30 minute increments from a start to stop time.  Basically from 8 AM Thursday to 5 PM the following Sunday.  I need it in a column and format such as Thursday, June 1, 2007 8:00 AM.  Please help.  If there is a turorial available just point the way!

Peace,
B
Link to comment
Share on other sites

I know it's a bit messy, but this should work.

[code]<?php
$min = 0;

do {

$curdate = date('l, F d, Y h:i A', mktime(8, 0 + $min, 0, 01, 18, 2007));
echo $curdate . "</br>";

$min = $min + 30;

$currentdate = mktime(8, 0 + $min, 0, 01, 18, 2007);
$findate = mktime(17, 0, 0, 01, 21, 2007);

} while ($currentdate <= $findate) ?>[/code]

EDIT :- BETTER VERSION

[code]
<?php
$min = 0;

do {

$curdate = mktime(8, 0 + $min, 0, 01, 18, 2007);
echo date('l, F d, Y h:i A', $curdate) . "</br>";


$findate = mktime(17, 0, 0, 01, 21, 2007);
$min = $min + 30;
} while ($curdate < $findate)
?>[/code]
Link to comment
Share on other sites

Here's another solution, using just the strtotime() and date() functions:

[code]<?php
$start_time = strtotime('1/25/2007 8:00 AM');
$end_time = strtotime('this sunday 5:00 PM',$start_time);
for ($i = $start_time;$i<=$end_time;$i += 1800) // 1800 is the number of seconds in 30 minutes
  echo date('l, F j, Y g:i A',$i).'<br>';
?>[/code]

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.