Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    13
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Help! Problem with Display the Date in Weekly table

    Hi, I want to show a booking table as below with the current week (date and day) and time:

    Time/Date | Mon,10-03-08 | Tue, 11-03-08 |....| Sun, 16-03-08 |
    ---------------------------------------------------------------
    0800-0900|
    0900-1000|
    1000-1100|
    1100-1200|
    ---------------------------------------------------------------

    How can I make the date and day in the table above to be updated automatically?
    I had try to figure it out a few days, but still can't get the correct display.
    And would it possible to show the previous and next week as well by using PHP?

    This the code that I'm using to generate the date:
    <?php
    $days_ahead = 0;
    $days_to_count = 8;

    for ($i=0;$i<$days_to_count;$i++)
    {
    $jump=$i+$days_ahead;
    $evalday = mktime(strftime ("%m/%d", strtotime("+$jump days")));
    $theday = strftime("%A", strtotime("+$jump days"));
    if($theday != "Sunday")
    {
    $days = $days_ahead+$i;
    $the_days[$j] = strftime("%Y-%m-%d ", strtotime("+$jump days"));
    $j++;
    }
    }
    $k = $days_ahead;

    foreach($the_days as $eachday)
    {
    echo "<td align= center>$eachday</td> ";
    $k++;
    } ?>

    It can run but does not really show what I want.
    Anyone who knows how to solve this problem, kindly give your suggestions, thanz~~

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The PHP function date() will give you the weekday by number (0 = Sunday, 6 = Saturday). So to find the Sunday prior to the current day (which will give you the start of the current week), simply subtract this weekday number from current date. (Remember that mktime() works in terms of seconds so one day equals 60 seconds * 60 minutes * 24 hours.) Once you have The date that is Sunday, use a loop to display the next 7 days.

    Previous and next week can be determined by subtracting 7 days and adding 7 days to the found Sunday respectively.

    PHP Code:
    //find current week's beginning
    $currentWeekSunday mktime() - (date("w") * 60 60 24);

    //display the week's dates
    for ($i 0$i 6$i++) {
        echo 
    "Date: " date("'l dS \of F Y", ($currentWeekSunday 60 60 24)) . "<br />\n";


  • Users who have thanked Fumigator for this post:

    Chiong (03-10-2008)

  • #3
    New Coder
    Join Date
    Mar 2008
    Posts
    13
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks for ur information, Fumigator
    I will try it out, have a nice day!

    Chiong


  •  

    Posting Permissions

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