I'm having a problem storing the date correctly in a MySQL database table under the column name 'publicationDate' via an html form.
// Contruct Of The Data
public function __construct($data=array()) {
if (isset($data['id'])) $this->id = (int) $data['id'];
if (isset($data['publicationDate'])) $this->publicationDate = (int) $data['publicationDate'];
if (isset($data['content'])) $this->content = $data['content'];
}
// Values To Post/Store For The Webpage Forms
public function storeFormValues ($params) {
$this->__construct($params);
if (isset($params['publicationDate'])) {
$publicationDate = explode ('-', $params['publicationDate']);
if (count($publicationDate) == 3) {
list ($y, $m, $d) = $publicationDate;
$this->publicationDate = mktime (0, 0, 0, $m, $d, $y);
}
}
}
The My SQL Column 'publicationDate' datatype is 'TIMESTAMP()' 'NOT NULL' default 'CURRENT_TIMESTAMP'. the date is to be stored & formatted '0000-00-00 00:00:00'.
The HTML form input for 'publicationDate' which is an edit form that is hidden and not to be edited is as:
<input type="hidden" name="publicationDate" id="publicationDate" value="<?php if ($results['article']->id ==true) { echo date("Y-m-d g:i:s", $results['article']->publicationDate);} else { echo date("Y-m-d g:i:s");}?>"/>
It'll store the date like this - '0000-00-00 00:00:00' which is 'yyyy-mm-dd hh:mm:ss' but only the year, month, & day will show correctly. The hour, minutes, & seconds will always appear in MySQL all zeros (00:00:00). This is obviously a problem when display/listing my data 'DESC' which is of course most recent being at the top of the list.