I can't figure this out, I'm sure it's very easy and I'm approaching it the wrong way. I have a mysql items db with a column name datePur and type datetime.
Sample data;
+---------------------+
| datePur |
+---------------------+
| 2015-11-03 11:05:00 |
+---------------------+
| 2014-12-02 07:14:11 |
+---------------------+
| 2015-08-01 11:09:34 |
+---------------------+
I have two forms in my web app, view and edit.
The view form retrieves the db data and displays the date in a read only table field in the following format; (03-11-2015)
<td><input type='text' name='datePur' value="<?php echo date("d-m-Y", strtotime($datePur)); ?> disabled"></td>
This works as expected.
My edit form retrieves the same data, however this time allowing the user to edit the date if necessary. The date is displayed to the user in the following format (not what I want); (2015-11-03 11:05:00)
<td><input type='text' name='datePur' value="<?php echo $datePur; ?>"></td>
I use the following code to post the data to the database;
edit.php
if (isset($_POST['btn-update'])) {
$datePur = ($_POST['datePur']);
}
function.php
public function update($datePur) {
try {
$stmt = $this->db->prepare("UPDATE items SET datePur=:datePur");
$stmt->bindParam(":datePur", $datePur);
$stmt->execute();
return true;
} catch (PDOException $e) {
echo $e->getMessage();
return false;
}
}
The form will only submit if I enter the date in the format Y-M-d h:i:s - the same format as it's presented. I can't for example enter 03-11-2015, as the form won't submit.
I'd like to keep the date format consistent to end users. I'd like the datetime always to be displayed to the end-user in the format d-m-Y. However I would like it inserted to the database in the format Y-M-d h:i:s
Any advice is appreciated.