Jump to content

HELP with php sql insert statement


jigen7

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/72718-help-with-php-sql-insert-statement/
Share on other sites

 

$new_val=strtotime($arr[7]);

$into_db=date("Y-m-d H:i:s",$new_val);

 

//or $into_db=date("Y-d-m H:i:s",$new_val); depending on whether $arr[7] is America(mm/dd/yyyy) or English date format(dd/mm/yyyy)

 

$sql = "INSERT INTO Links(URL,Title,Description,Email,SubmitURL,ContactedOn)

      VALUES('{$arr[0]}','{$arr[1]}','{$arr[2]}','{$arr[3]}','{$arr[4]}','$into_db"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.