MySQL and PHP inserting a date into a Date field -


i have date so: 07/15/2015 , trying insert date date database column. problem date database saves date 0000-00-00 how date save 2015-07-15 here code using insert:

function insertcareer($connection, $date, $title, $text){                   if($stmt = $connection->prepare("insert `careers` (date, title, text) values (?, ?, ?)")){                         $stmt->bind_param('sss', $date, $title, $text);                         $stmt->execute();                         $stmt->close();                         echo 'career has been added <br>';                 }          } 

how can fix this?

mysql not understand date in format you're providing it. considering ambiguous anyway (d/m/y in europe, m/d/y in usa), should pass dates around y/m/d.

select cast('07/01/2015' date); -- null select cast('2015/07/01' date); -- 2015-07-01 

so use make work:

$date = date('y-m-d', strtotime($date)); 

argh, beat 15 seconds.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -