2 Replies Latest reply on Sep 12, 2007 10:57 AM by Newsgroup_User

    Adjusting Time in PHP

    AngryCloud Level 1
      If I have a timestamp from a record on a page ( <?php echo $row_recordset['timestamp']; ?> ) and I want to output the time to be 2 hours ahead of the timestamp, how do I do that?
        • 1. Adjusting Time in PHP
          Ninjabear_adobe
          Taken from the manual at: http://uk2.php.net/manual/en/function.date.php:

          ------------------
          It is possible to use date() and mktime() together to find dates in the future or the past:

          Example 438. date() and mktime() example

          <?php
          $tomorrow = mktime(0, 0, 0, date("m") , date("d")+1, date("Y"));
          $lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y"));
          $nextyear = mktime(0, 0, 0, date("m"), date("d"), date("Y")+1);
          ?>
          ------------

          Mktime takes the format of hr, min, sec, month, day, year. You would have to do something like this though using your example:

          <?php
          $ts = $row_recordset['timestamp'];

          $tomorrow = mktime(date('H',$ts)+2, date('i',$ts), date('s',$ts), date('m',$ts) , date('d',$ts), date('Y',$ts));
          ?>
          • 2. Re: Adjusting Time in PHP
            Level 7
            .oO(Ninjabear_adobe)

            > <?php
            > $ts = $row_recordset['timestamp'];
            >
            > $tomorrow = mktime(date('H'$ts)+2, date('i'$ts), date('s'$ts), date('m'$ts)
            >, date('d'$ts), date('Y'$ts));
            > ?>

            Some other ways:

            * $row_recordset['timestamp'] + 7200
            * strtotime()
            * A query that already returns the adjusted timestamp.
            * ...

            Micha