1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Calendar functionality

Discussion in 'PHP' started by neilfurry, Nov 26, 2017.

  1. #1
    Hi Mate,

    im having a problem getting the correct month when im on the last week of the month. please see my attachment. question.png

    here is my code:

    $date = isset($_POST['dd'])? date("Y-m-d",strtotime($_POST['dd'])) : date("Y-m-d");

    //echo $_POST['dd'];
    //echo date("Y-m-d",strtotime($_POST['dd']));

    // parse about any English textual datetime description into a Unix timestamp
    $ts = strtotime($date);
    // calculate the number of days since Monday
    $dow = date('w', $ts);
    $offset = $dow - 1;
    if ($offset < 0) {
    $offset = 6;
    }
    // calculate timestamp for the Monday
    $ts = $ts - $offset*86400;

    for ($i = 0; $i < 7; $i++, $ts += 86400){
    //My code here...
    }
     
    neilfurry, Nov 26, 2017 IP
  2. Absolute.Hosting

    Absolute.Hosting Member

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    First thing I would check is be sure you're calculating the number of days in each month correctly (including leap year).
     
    Absolute.Hosting, Nov 28, 2017 IP
  3. neilfurry

    neilfurry Active Member

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #3
    Up... still need a clear understanding on what i need please.

    Thank you
     
    neilfurry, Dec 3, 2017 IP
  4. Einheijar

    Einheijar Well-Known Member

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    3
    Trophy Points:
    165
    #4
    Why not just use a proper datepicker? Failing that each item (date) should store the complete date to prevent issues like the above from happenning
     
    Einheijar, Dec 4, 2017 IP
  5. neilfurry

    neilfurry Active Member

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #5
    This is a custom calendar having displayed users on the left side of the week. so date picker is not possible..

    can you help?

    thank you
     
    neilfurry, Dec 5, 2017 IP
  6. Einheijar

    Einheijar Well-Known Member

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    3
    Trophy Points:
    165
    #6
    No idea how you generated the code for the calendar display itself but each item should have the complete date inside.

    If you view an example like http://www.php-calendar.org/php-calendar/ each date item has YYYY-MM-DD encapsulated within itself so you won't have to worry about overflowing like you did
     
    Einheijar, Dec 5, 2017 IP
  7. neilfurry

    neilfurry Active Member

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #7
    i think i need to explain further, in order to make it more clearer.

    on the calendar that i want to create, the first thing a user can see is the current week then it will depend on what week it will display on the date the user will be choosing on a separate datepicker field.

    1. The calendar has a list of users on the left side
    2. Each users has a list of days of the week selected from a datepicker
    3. The display is fine,. the only problem is the date Nov. 27-30 is correct while 1,2 and 3 should be already December
    but when i look into the source code, it show me that 1,2 and 3 is still November. I need to make it that when im on that scenario of the week where the dates of two months meet, the dates of the new month should show on the source code that it is for the new month and not for the previous month.
    4. As you can see on the source code when i select 3 it tells me that it still November 3 where it should be December 3 users.png

    souce code:

    dt.png
     
    neilfurry, Dec 5, 2017 IP