SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast alsaffar's Avatar
    Join Date
    Aug 2002
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding hours to NOW() function

    Hi there,

    I have a problem of NOW() function that I'm using when I want to insert the DATETIME in my table.

    The problem is the time that will be inserted in the DB is the server time which is in my case is GMT time. what should I do incase I want to add 3 hours on that day before I insert it in the DB. How I can reach my target?
    HaVe a GooD DaY

    @li @l$@ff@R

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    date_add(now(), interval 3 hour)

  3. #3
    SitePoint Guru dragonhawk's Avatar
    Join Date
    Apr 2002
    Location
    Melbourne
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    3 hours = 3 * 60 * 60 seconds = 10800 seconds

    time()+10800 to add 3 hours to the current time...

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by jofa
    date_add(now(), interval 3 hour)
    Same thing written a different way

    NOW() + INTERVAL 3 HOUR

  5. #5
    SitePoint Enthusiast alsaffar's Avatar
    Join Date
    Aug 2002
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is cool for the NOW() function in SQL.

    But how can I add 3 hours in UNIX to the following formula:

    $CurrentTime = date ("l dS of F Y h:i:s A");
    HaVe a GooD DaY

    @li @l$@ff@R

  6. #6
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    OsnabrŘck
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Without somekind of converting the formatted date back into a unixtimestamp this is not possible. Do you store the timestamp in that format?

    To create a timestamp for 3 hours ahead using your format, you have to pass in the time() argument as mentioned before:

    PHP Code:
    $CurrentTime date ("l dS of F Y h:i:s A"time() + 10800); 


Bookmarks

Posting Permissions

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