gpt4 book ai didi

mysql - 查看 Hook 仅显示 1969 年日期

转载 作者:行者123 更新时间:2023-11-29 14:43:35 24 4
gpt4 key购买 nike

我有一个看起来像这样的表格:

+--------------------+-------------+------+-----+---------+-------+
| 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 | |
+--------------------+-------------+------+-----+---------+-------+

我正在编写一个模块,以便可以在 Drupal 6 View 中查看该表。

我按照我在这里找到的示例进行操作: http://drupalcontrib.org/api/drupal/contributions--views--docs--docs.php/function/hook_views_data/6

所以我将 download_date 暴露为:

    $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',
),

);

但是当我将其添加到 View 中时,所有日期都显示为“12/31/1969 - 19:33”。我的表格中的日期都不是:

编辑:更正的查询:

 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)

我还在 View 中使用格式“r”制作了自定义日期格式,我得到了所有日期均为 1969 年 12 月 31 日星期三 19:33:31 -0500。

那么我的模块做错了什么?

最佳答案

您的查询:

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

这里的问题是 MySQL 期望以不同的格式给出日期。

您需要按以下格式提供日期:

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

(您可以根据需要删除微秒、秒等以获得所需的精度)

因此,在您的情况下,您的查询应如下所示:

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

这应该正确查询该字段。

顺便说一句 - 如果您的日期意外地显示为 1969 年,则意味着您可能在其他查询中也使用了错误的格式。您可能也想检查一下。

有关日期时间,请参阅 MySQL 手册页:http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

关于mysql - 查看 Hook 仅显示 1969 年日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7484479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com