zibrnp Posted January 16, 2018 Share Posted January 16, 2018 Hello, - I have date and time in format "12/26/2017 00:00:00". $raw_date = $row[3]." 00:00:00"; Since I need it in the format "2017-12-26 00:00:00" I am doing $date_obj = DateTime::createFromFormat("m/d/Y H:i:s", $raw_date); $formated_date = $date_obj->format('Y-m-d H:i:s'); before I send it to DB I do: $date = mysqli_real_escape_string($dbc, trim(stripcslashes($formated_date))); and I end up with "2017-10-06 00:00:00" in the database instead of "2017-12-26 00:00:00". I do not understand why, any suggestion please? Quote Link to comment Share on other sites More sharing options...
Barand Posted January 16, 2018 Share Posted January 16, 2018 I admit I am puzzled. I created a test table CREATE TABLE datetest ( date DATETIME NOT NULL PRIMARY KEY )then ran this $raw_date = '12/26/2017 00:00:00'; $date_obj = DateTime::createFromFormat("m/d/Y H:i:s", $raw_date); $formated_date = $date_obj->format('Y-m-d H:i:s'); $date = mysqli_real_escape_string($dbh, trim(stripcslashes($formated_date))); $dbh->query("INSERT INTO datetest VALUES ('$date')"); "2017-12-26 00:00:00" was written to the table, as expected Quote Link to comment Share on other sites More sharing options...
zibrnp Posted January 16, 2018 Author Share Posted January 16, 2018 $q = "INSERT INTO pipedrive (id, activity_deal, activity_done, activity_note, activity_subject, activity_due_date, deal_183_RT_lease_number, deal_merchant_number, activity_creator, activity_ID, activity_last_notification_time, activity_marked_as_done_time, activity_type, activity_update_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $stmt = mysqli_prepare($dbc, $q); mysqli_stmt_bind_param($stmt, 'issssssssissss', $id, $activity_deal, $activity_done, $activity_note, $activity_subject, $activity_due_date, $deal_183_RT_lease_number, $deal_merchant_number, $activity_creator, $activity_ID, $activity_last_notification_time, $activity_marked_as_done_time, $activity_type, $activity_update_time); mysqli_stmt_execute($stmt); Do you see anything wrong with this? Quote Link to comment Share on other sites More sharing options...
Barand Posted January 17, 2018 Share Posted January 17, 2018 If you are using prepared statements then do not use mysqli_real_escape_string(). Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 17, 2018 Share Posted January 17, 2018 The real question is do YOU see anything wrong? Did you execute it and get any results? Any errors? Why do you want us tor review your code when you haven't tried it yet? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.