Help with php date

Discussion in 'PHP' started by levani, Apr 19, 2009.

  1. #1
    I send the current date to database using this code:

    gmdate("Y-m-d H:i:s")
    PHP:
    But the time is being sent incorrectly. The time is set incorrectly on my server! I want to send the time, what is in my country now, not what is set on users' computer or on the server.

    Is it possible? The database is mysql.

    Thanks in advance.
     
    levani, Apr 19, 2009 IP
  2. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #2
    PHP is not client side language !

    PHP sends YOUR server date/time, so .. if you can't check your clock, forget about it !
     
    ActiveFrost, Apr 19, 2009 IP
  3. levani

    levani Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Than why does it send different time when I change the time on my computer?

    What if my server is in different time zone than me?
     
    levani, Apr 19, 2009 IP
  4. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #4
    date_default_timezone_set('UTC'); ( change it to whatever you need )
     
    ActiveFrost, Apr 19, 2009 IP
  5. levani

    levani Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Where should I add this function if my code looks like this:

    if ($_POST['lev-post-content']) {
    
    
    $insert = "INSERT INTO " . $table_name .
                " (date, user_id, post_id, content) " .
                "VALUES (now(),'" . $wpdb->escape($_POST['lev-post-author-id']) . "','" . $wpdb->escape($_POST['lev-post-id']) . "','" . $wpdb->escape($_POST['lev-post-content']) . "')";
    
      $results = $wpdb->query( $insert );
    
    PHP:
     
    levani, Apr 19, 2009 IP
  6. tguillea

    tguillea Active Member

    Messages:
    229
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #6
    How much is the time off by? Is it always an exact amount or does it change?

    Regards,
    Tom Guilleaume
     
    tguillea, Apr 19, 2009 IP
  7. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #7
    Setting are always added at the top of all your code ( right under <?php ).
     
    ActiveFrost, Apr 19, 2009 IP
  8. levani

    levani Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    OK. Thanks for help very much!!!
     
    levani, Apr 19, 2009 IP
  9. cyno

    cyno Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    And if you are looking for a more advanced date object forget Zend_Date: it is very very low !
     
    cyno, Apr 19, 2009 IP