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
https://forums.phpfreaks.com/topic/34895-array-question/
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
https://forums.phpfreaks.com/topic/34895-array-question/#findComment-164538
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
https://forums.phpfreaks.com/topic/34895-array-question/#findComment-164564
Share on other sites

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.