SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    are the times server or user's local time?

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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?

  4. #4
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    server time

  5. #5
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Correct and yes next available 28 timeslots

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I dont have any more spare time to spend.

    Here is one way to get your next slot;
    PHP Code:

    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •