Create list of next 7 days with times

I’m trying to add ability to choose a future publishing date/time.
I need to create a list with times 09:00, 12:00, 15:00, 18:00 for each of the next 7 days including today.
Obviously I don’t want to display a date/time in the past, so if it is now (eg) Tues 10 Jan 11:00 I would want the following:

Tues 10 Jan 12:00
Wed 10 Jan 15:00
Thurs 10 Jan 18:00
Fri 11 Jan 09:00
etc…
Tues 17 Jan 12:00

are the times server or user’s local time?

Tues 10 Jan 12:00
Wed 10 Jan 15:00
Thurs 10 Jan 18:00
Fri 11 Jan 09:00

Presumably you meant:

Tues 10 Jan 12:00
Tues 10 Jan 15:00
Tues 10 Jan 18:00
Weds 11 Jan 09:00

Storing these date/time options in a database, as timestamps such as : 2011-01-10 15:00:00 correct?

Did you mean next 7 days, or did you mean the next 28 possible time slots?

server time

Correct and yes next available 28 timeslots

I dont have any more spare time to spend.

Here is one way to get your next slot;



function getNextSlot(){
// $now = time() - (36000*10); // how to spoof this morning, 10 hrs ago for me
$now = time();
$slots = array('9am today','12pm today','2pm today','6pm today', '9am tomorrow');

  foreach( $slots as $k=>$slot){
     if ( $now > strtotime($slots[$k]) && $now < strtotime($slots[$k+1]))
          return $slots[$k]; 

    if( $now < strtotime($slots[0])) // in case time is before 9am
          return $slots[0];

   }
}
echo '<b>' . getNextSlot() . '</b>';

// gives 

6pm today


Youd then just create another array of times,

$times = array(‘9am’, ‘12am’ … );

and generate the next 7 days …

There’s likely a better way to do it, but I must away – just a first bash still, HTH.