开发者

View hook only displays 1969 dates

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--view开发者_JAVA百科s--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?


Your query:

select count(1) from products_downloaded where download_date <'12/31/2000 -  19:33'

Your problem here is that MySQL expects dates to be given in a different format to that.

You need to provide your dates in the following format:

'2007-12-31 23:59:59.999999'

(you can drop the microseconds, seconds, etc to get the precision you need as required)

So in your case, your query should look like this:

select count(1) from products_downloaded where download_date <'2000-12-31 19:33'

This should query the field correctly.

By the way -- If you have dates showing up unexpectedly as 1969, it implies that perhaps you've been using the wrong format in other queries as well. You may want to check that too.

See the MySQL manual page for date times: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜