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
    New Coder
    Join Date
    Jan 2011
    Posts
    79
    Thanks
    7
    Thanked 0 Times in 0 Posts

    adding 2 hours to now()??

    in my MySql database i have a field "created_at" = now()
    for ex: 2011-05-23 11:47:28

    i need to add two hours to that so i have 2011-05-23 13:47:28
    how will i do this please?

    i have this so far but it is not correct:

    $currentTime = time($msg->getCreatedAt());
    $timeAfterOneHour = $currentTime+60*60;
    $date=date("Y-m-d H:i:s",$timeAfterOneHour);

    please help
    thank you

  • #2
    New Coder
    Join Date
    Dec 2007
    Posts
    68
    Thanks
    25
    Thanked 2 Times in 2 Posts
    you can use this...

    DATE_ADD(NOW(), INTERVAL 2 HOUR)

    hope that helps

  • #3
    New Coder
    Join Date
    Jan 2011
    Posts
    79
    Thanks
    7
    Thanked 0 Times in 0 Posts
    is this php code?

  • #4
    New Coder
    Join Date
    Apr 2008
    Location
    Blagoevgrad, Bulgaria
    Posts
    47
    Thanks
    0
    Thanked 8 Times in 8 Posts
    Try like this:
    PHP Code:
    $currentTime time($msg->getCreatedAt());
    $timeAfterOneHour $currentTime+(60*60*2);
    $date=date("Y-m-d H:i:s",$timeAfterOneHour); 

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,329
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    You can also use date() with a relative time format.

    PHP Code:
    $currentTime time($msg->getCreatedAt()); 
    $date=date("Y-m-d H:i:s"strtotime("+2 hours"$currentTime)); 
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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