Question:

How to add 5 hours to PHP time?

by  |  earlier

0 LIKES UnLike

How to do get system date and time through php and add 5 hours to the time portion and display it like:

Sunday 10th of August 2008 05:54:43 AM

 Tags:

   Report

3 ANSWERS


  1. There is a much easier way to do this.  Use the built in strtotime function.

    <?php

    $time = strtotime("+5 hours");

    print date('l jS \of F Y h:i:s A', $time);

    ?>

    Hope this helps.

    P.S. Not all of us are useless


  2. <?php

    function addTime($hours=0, $minutes=0, $seconds=0 )

    {

    $totalHours = date(”H”) + $hours;

    $totalMinutes = date(”i”) + $minutes;

    $totalSeconds = date(”s”) + $seconds;

    $timeStamp = mktime($totalHours, $totalMinutes, $totalSeconds);

    $myTime = date(” H:i:s A”, $timeStamp);

    return $myTime;

    }

    ?>

  3. <?php

    $time = time() + 5;

    ?>

    I think thats it, but i'm not sure, it's def. time() + something.

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions