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,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    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)); 
    I can't really think of anything to write here now...


  •  

    Posting Permissions

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