HELP with php sql insert statement value format!

Discussion in 'PHP' started by jigen7, Oct 10, 2007.

  1. #1
    suppose $arr7 contains this value '10/5/2007 6:02' how can i format that to be change like this '2007-01-22 08:55:19' when im going to use it in a insert statement here's the code

    $sql = "INSERT INTO Links(URL,Title,Description,Email,SubmitURL,ContactedOn)
    VALUES('{$arr[0]}','{$arr[1]}','{$arr[2]}','{$arr[3]}','{$arr[4]}','{$arr[7]}')"

    original value format = 10/5/2007 6:02
    target value format before storing to sql = 2007-01-22 08:55:19
     
    jigen7, Oct 10, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Your original date does not contain seconds, so in the new one it'll always be 00.

    
    $old = '10/5/2007 6:02';
    $new = date('Y-m-d H:i:s', strtotime($old));
    
    echo $new;
    
    PHP:
     
    nico_swd, Oct 11, 2007 IP