Store Time in MySQL + 5 HOURS - PHP

Discussion in 'PHP' started by you-cubez, Jun 6, 2007.

  1. #1
    Hi - Does anyone know to store the CURRENT TIME + 5 HOURS in MySQL using a 'Time' Field....?

    Many Thanks!! :)
     
    you-cubez, Jun 6, 2007 IP
  2. Wyla

    Wyla Well-Known Member

    Messages:
    924
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    140
    #2
    First do the normal CURRENT TIME (an option in MYSQL) then in another line of code just add 5 hours.
     
    Wyla, Jun 6, 2007 IP
  3. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    There's a number of ways. Some examples:

    $query = "UPDATE tableName SET timeField = NOW() + INTERVAL 5 HOUR";
    $query = "UPDATE tableName SET timeField = '" . date("Y-m-d H:i:s", time()+(5*3600)) . "'";
    $query = "UPDATE tableName SET timeField = '" . date("Y-m-d H:i:s", strtotime("+5 hours")) . "'";
    PHP:
     
    phper, Jun 6, 2007 IP
  4. you-cubez

    you-cubez Active Member

    Messages:
    842
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Many Thanks!!!
     
    you-cubez, Jun 7, 2007 IP
  5. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #5
    simple!

    1. Define the type in database table. like (date or time)
    2. Just use now() in the query.

     
    olddocks, Jun 7, 2007 IP
  6. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #6
    phper's solution is good :)
     
    coderbari, Jun 7, 2007 IP
  7. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #7
    phper's solution is correct. :)
     
    ansi, Jun 7, 2007 IP
  8. you-cubez

    you-cubez Active Member

    Messages:
    842
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    60
    #8
    Thanks guys! I originally had:

    ADDTIME(CURTIME(), '5:00')

    But that just added 5 as a number on - so if someone registered at 23:20 it would store as 28:20!! Thanks again
     
    you-cubez, Jun 7, 2007 IP