Php Time help

Discussion in 'PHP' started by turbohacker, Oct 4, 2010.

  1. #1
    Okay im trying to create a script which fetches the date, adds three days, then updates this new date and time in the mysql db.

    I've read the php manual on time, and I'm still confused. Im useless.


    So far I have this:

    $mysql_host    = "localhost";
    $mysql_username = "username";
    $mysql_password = "password";
    $mysql_database = "database";
    $id   = $_REQUEST['id'];
    
    
    mysql_query("UPDATE db.table SET time=$thetime WHERE id='"$id"'") or die(mysql_error());
    mysql_close();
    PHP:
    I need the time/date format like this:

    2010-10-04 17:45:21


    Please help, thanks :)
     
    Last edited: Oct 4, 2010
    turbohacker, Oct 4, 2010 IP
  2. turbohacker

    turbohacker Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Figured it out now... took me awhile but I came up with this, please advise if anyone else can think of better method.

    <?php
    
    $year = date("Y:m:d");
    $time = date("G:i:s");
    $future = date("Y:m:d", strtotime("+3 day"));
    
    print "$year $time - - $future $time ";
    
    ?>
    PHP:
     
    turbohacker, Oct 4, 2010 IP
  3. turbohacker

    turbohacker Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Okay, I am having a problem with script... please help...

    Error:

    Parse error: syntax error, unexpected T_VARIABLE

    Im guessing in the mysql query, please help.

    <?php
    
    include('include/config.php');
    include('include/function.php');
    
    $future = date("Y:m:d G:i:s", strtotime("+3 day"));
    
    $mysql_host    = "localhost";
    $mysql_username = "user";
    $mysql_password = "pass";
    $mysql_database = "db";
    
    $UID = $_REQUEST['UID'];
    
    mysql_query("UPDATE subscriber SET expired_time='"$future"' WHERE UID='"$UID"'") or die(mysql_error());
    mysql_close();
    
    
    ?>
    
    PHP:
     
    turbohacker, Oct 4, 2010 IP
  4. yogabalan

    yogabalan Member

    Messages:
    106
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #4
    i thing you have not connected to mysql. did u? atleast can you tell what error says?
     
    yogabalan, Oct 5, 2010 IP
  5. zinalshah

    zinalshah Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try this

    mysql_query("UPDATE subscriber SET expired_time='".$future."' WHERE UID='".$UID."'") or die(mysql_error());
     
    zinalshah, Oct 5, 2010 IP
  6. yogabalan

    yogabalan Member

    Messages:
    106
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #6
    this is correct
    mysql_query("UPDATE subscriber SET expired_time='$future' WHERE UID='$UID'") or die(mysql_error());
     
    yogabalan, Oct 5, 2010 IP
  7. veroxii

    veroxii Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    veroxii, Oct 5, 2010 IP
  8. imperialDirectory

    imperialDirectory Peon

    Messages:
    395
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #8
    How about:
    
    mysql_query("UPDATE `db`.`table` SET `time` = ADDDATE(NOW(), 3) WHERE `id` = '$id'") or die(mysql_error());
    
    Code (markup):
     
    imperialDirectory, Oct 6, 2010 IP
  9. turbohacker

    turbohacker Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    thanks for the tips :)
     
    turbohacker, Oct 7, 2010 IP
  10. sinha.sidhi

    sinha.sidhi Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    yes it is correct.....
     
    sinha.sidhi, Aug 29, 2011 IP