I have a table that looks like:
+--------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+-------------+------+-----+---------+-------+
| ProductsDownloadId | int(11) | NO | PRI | 0 | |
| RCContactID | int(11) | NO | MUL | NULL | |
| product_name | varchar(50) | YES | MUL | NULL | |
| download_date | timestamp | YES | | NULL | |
+--------------------+-------------+------+-----+---------+-------+
I’m writing a module for this table to be viewable in a Drupal 6 View.
I followed the example I found here:
http://drupalcontrib.org/api/drupal/contributions–views–docs–docs.php/function/hook_views_data/6
So I exposed the download_date as thus:
$data['products_downloaded']['download_date']=array(
'title'=>t("Download Date"),
'help'=>t("When Product was downloaded by the user"),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
But when I add it to a view, all the dates are displayed as “12/31/1969 – 19:33”. And none of the dates in my table are:
EDIT: Corrected query:
mysql> select count(1) from products_downloaded where download_date <'2000-12-31 23:59:59.999999';
+----------+
| count(1) |
+----------+
| 0 |
+----------+
1 row in set (0.04 sec)
I also did a custom date format with the format ‘r’ in the View and I got
Wed, 31 Dec 1969 19:33:31 -0500 for all the dates.
So what did I do wrong on my module?
What I was able to determine was that PHP or Drupal wasn’t able to understand whatever was being returned to the processor. I messed around with a custom hook and got the value to be accepted by the DateTime constructor. From there . . . it was easy to get the date formats back.