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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    518
    Thanks
    25
    Thanked 0 Times in 0 Posts

    mktime(0,0,0,date("m")+1 issue...

    hi peeps im having issues with:

    mktime(0,0,0,date("m")+1,date("d"),date("Y"));

    the problem im seeing is that +1 on the month is going to the month after next. since today is the 31st it seems to fall over as next month doesnt have 31 days so it skips to may!

    im using the following script lazily copy and pasted 12 times for a 12 month calendar (was a rush job so i never got round to sticking this as a function and looping properly)

    basically this makes a holiday calendar type of thing

    thanks to anyone that can help. btw this worked fine yesterday so its definately an issue with the 31st. i hate using dates in php lol

    PHP Code:
    $date time ();
    $day date('d'$date);
    $month date('m'$date);
    $year date('Y'$date);
    $first_day mktime(0,0,0,$month1$year);
    $title date('F'$first_day);
    $day_of_week date('D'$first_day);
    switch(
    $day_of_week) {
        case 
    "Sun"$blank 0; break;
        case 
    "Mon"$blank 1; break;
        case 
    "Tue"$blank 2; break;
        case 
    "Wed"$blank 3; break;
        case 
    "Thu"$blank 4; break;
        case 
    "Fri"$blank 5; break;
        case 
    "Sat"$blank 6; break;
    }

    $days_in_month cal_days_in_month(0$month$year);

    $data "<div class='tableheadNoLink'>" strtoupper($title) . " $year</div>\n";
    $data .= "<div class='layouttable'>\n";
    $data .= "<table class='listtable' cellspacing='0'>\n";
    $data .= "<tr>\n<th>Sunday</th>\n<th>Monday</th>\n<th>Tuesday</th>\n<th>Wednesday</th>\n<th>Thursday</th>\n<th>Friday</th>\n<th>Saturday</th>\n</tr>\n";

    $day_count 1;

    $data .= "<tr>";

    while ( 
    $blank ) { 
        
    $data .= "<td valign='top' style='padding:0'> &nbsp; </td>\n"
        
    $blank $blank-1
        
    $day_count++;
    }

    $day_num 1;
    $today date('Y-m-d');
    while (
    $day_num <= $days_in_month) { 

        if(
    strlen($day_num) < 2) {
            
    $day_num2 "0" $day_num;
            
    $thisdate "$year-$month-$day_num2";
        } else {
            
    $thisdate "$year-$month-$day_num";
        }

        if(
    $thisdate != $today) {
            
    $highlight "";
        } else {
            
    $highlight " style='background-color:#f8981d; text-align:center; color:#FFFFFF'";
        }

        
    $data .= "<td valign='top' style='padding:0'><div$highlight><strong>&nbsp;$day_num&nbsp;</strong></div>";

        
    $query  "SELECT id, trading_name, night_out, jobRefPicker, number_workers, date_worked FROM subcontractor_timesheets WHERE date_worked='$year-$month-$day_num' ORDER BY trading_name";
        
    $result mysql_query($query);
        
        while(
    $row mysql_fetch_array($resultMYSQL_ASSOC)) {
        
            if(
    $row['night_out'] == "1") {
                
    $appr "<div class='night' id='timesheet{$row['id']}'>";
            } else {
                
    $appr "<div class='day' id='timesheet{$row['id']}'>";
            }

            
    $abbname substr($row['trading_name'] , 011);
            
    $abbproject explode(" - "$row['jobRefPicker']);
            
    $abbprojectdesc strtolower($abbproject[1]);
            
    $abbprojectdesc ucwords($abbprojectdesc);
            
    $abbprojectfull $abbproject[0] . "<br />" substr($abbprojectdesc 014);

            
    $popup "<div class='timesheet_popup' id='popup{$row['id']}'>";
            
    $popup .= "<p><strong>Subcontractor:</strong><br />{$row['trading_name']}</p>";
            
    $popup .= "<p><strong>Date:</strong><br />" writeDate($row['date_worked']) . "</p>";
            
    $popup .= "<p><strong>Number of men:</strong><br />{$row['number_workers']}</p>";
            
    $popup .= "<p><strong>Project:</strong><br />{$abbproject[0]}<br />$abbproject[1]</p>";
            
    $popup .= "<p><a href=\"javascript:deleteSCTimesheet('{$row['id']}')\">Delete timesheet</a></p>";
            
    $popup .= "<p><a href=\"javascript:hideObject('popup{$row['id']}')\">Close popup</a></p>";
            
    $popup .= "</div>";

            
    $data .= "$popup$appr<a href=\"javascript:showObject('popup{$row['id']}')\">" $abbname " (" $row['number_workers'] . ")<br />";    
            
    $data .= "$abbprojectfull";
            
    $data .= "</a></div>";
        }
        
        
    $data .= "</td>\n";
        
    $day_num++; 
        
    $day_count++;

        if (
    $day_count 7) {
            
    $data .= "</tr>\n<tr>\n";
            
    $day_count 1;
        }
    }

    while ( 
    $day_count >&& $day_count <=) { 
        
    $data .= "<td valign='top' style='padding:0'> &nbsp; </td>\n"
        
    $day_count++; 
    }

    $data .= "</tr>\n</table>\n</div collapse>\n<br />";
    echo 
    $data;

    [
    COLOR="Red"]$date mktime(0,0,0,date("m")+1,date("d"),date("Y"));[/COLOR]
    then loops.... 
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by babelfish View Post
    the problem im seeing is that +1 on the month is going to the month after next. since today is the 31st it seems to fall over as next month doesnt have 31 days so it skips to may!
    One solution would be to use checkdate to determine whether the date is real.
    Are you a Help Vampire?

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    518
    Thanks
    25
    Thanked 0 Times in 0 Posts
    i thought it would +1 month though. so it is actually +1 month with the respective day. i guess i could set the next month to day 1 of the month seeing as that would be fine.

    i will look into checkdate thanks!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #4
    New Coder
    Join Date
    Mar 2010
    Posts
    26
    Thanks
    3
    Thanked 1 Time in 1 Post
    Isnīt that obvious?

    We are in march, so
    date("m")+1 = 04

    mktime(.... 04,31 ....) = may 1

    If you want to make a step from last of one month to last of next month, you have to calculate the amount of days that month has, and use

    date("d") + days;

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    518
    Thanks
    25
    Thanked 0 Times in 0 Posts
    lmao. this was so easy to fix in the end!

    $date = mktime(0,0,0,date("m")+1,date(1),date("Y")); so it gets day1 of the next month.

    sorry to waste you time. move on nothing to see here
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson


  •  

    Posting Permissions

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