im trying to compensate for an hour and minute difference on our server using::

// this is supposed to increase the 'h'  hour +1 and 'i'  minute + 10

// format the time layout
$today = getdate(mktime(date('h i a F l Y')+1,+10));


// set vars from array
$day = $today['mday']; 
$weekday = $today['"weekday'];
$month = $today['month']; 
$year = $today['year']; 
$hour = $today['hours'];
$minutes = $today['minutes'];

// echo results
echo $day.' '.$weekday.' '.$month.' '.$year.' '.$hour.':'.$minutes; 

?>

but im getting strage results! hmm

@ 12:08am i get

25 July 2003 13:10
what i is "Friday July 2003 13:18 am"

    // Get the current date and time info.
    $current_time = getdate();
    
    // Compensate hours and minutes accordingly, and set variables
    $comphours = $current_time['hours']+1;
    $compminutes = $current_time['minutes']+10;
    $month = $current_time['mon'];
    $day = $current_time['mday'];
    $year = $current_time['year'];
    
    // Get the current date and time info with the compensation applied.
    $today = date("h:i a l F j, Y", mktime($comphours, $compminutes, 0, $month, $day, $year));
    
    // echo results 
    echo $today;
    

      Simple...

      just change

      $hour = $today['hours']; 
      $minutes = $today['minutes'];
      

      to..

      $hour = $today['hours']+1; 
      $minutes = $today['minutes']+10; 
      

      and remove +1,+10 from mktime.

        ...Or replace the whole lot with

        strtotime('1 hour 10 minutes');

          replace what with

          strtotime('1 hour 10 minutes');

          ?

          TW

            Yeah, I forgot you can mix offsets (like hours and minutes) using strtotime()...

            // Get the current Unix timestamp with the offset. 
            $time_offset = strtotime("1 hour 10 minutes");
            
            // Convert the timestamp to the format you desire.
            $today = date("h:i a l F j, Y", mktime($time_offset));
            

            Or, you should be able to do it all in one step.

            $today = date("h:i a l F j, Y", mktime(strtotime('1 hour 10 minutes')));
            

              Matter of fact, you won't need the mkttime() call; strtotime() itself returns a suitable timestamp.

                OK, without the mktime...

                // Get the current Unix timestamp with the offset. 
                $time_offset = strtotime("1 hour 10 minutes"); 
                
                // Convert the timestamp to the format you desire. 
                $today = date("h:i a l F j, Y", $time_offset);
                
                  $today = date("F jS Y, h:i a", strtotime('1 hour 10 minutes'));
                  

                  thats all you need... outouts "July 25th 2003, 11:59 am"

                    Yeah, I personally prefer to set the variable, because I would inevitably need it some time later, so it just makes it easier for me. 😉

                    That's just my luck I can be a variable pac rat...

                      well, atleast thewomb has many options to choose 😉

                        Write a Reply...