帮助进行 MySQL Unix 时间戳查询

发布于 2024-09-11 11:33:52 字数 1039 浏览 2 评论 0原文

我正在尝试创建一个自定义 MySQL 以与 Expression Engine CMS 一起使用。查询的目的是显示今天或将来发生的事件。

问题在于 EE 字段类型允许您放入日期并将其转换为 unix 时间戳。如果我选择 7 月 26 日,它会输入日期值“7 月 25 日 23:00”。

正如您从下面的查询中看到的,它几乎可以工作,但我需要在语句条件部分使用的值上添加 24 小时。我希望“例如今天 7 月 25 日”当天发生的事件一直显示到当天 23:00,然后将其删除。 我几乎已经知道了,只是不知道如何在条件中添加 24 小时。

           SELECT t.entry_id, 
                       t.title, 
                       t.url_title, 
                       d.field_id_13 AS event_lineup, 
                       d.field_id_14 AS event_details, 
                       d.field_id_15 AS event_day, 
                       d.field_id_16 AS event_flyer_front, 
                       d.field_id_17 AS event_flyer_back, 
                       d.field_id_18 AS event_facebook, 
                       d.field_id_12 AS event_date 
             FROM `exp_weblog_titles` AS t 
NATURAL JOIN `exp_weblog_data` AS d 
           WHERE d.weblog_id = 5 
               AND CAST(d.field_id_12 AS UNSIGNED) >= (unix_timestamp(Now())) 
      ORDER BY d.field_id_12 ASC

I am trying to create a custom MySQL for use with the Expression Engine CMS. The purpose of the query is to display events that are happening today or in the future.

The problem is that the EE field type that allows you to put in the date and converts it into a unix timestamp. If I pick the 26th July it puts in the date value "25th July 23:00".

As you see from my query below it almost works but I need to add 24 hours onto the values that are used in the conditional part of the statement. I want events that occur on the day "for example today 25th July" to be displayed up until 23:00 hours that day then be removed.
I almost have it I am just stuck on how to add 24 hours to the conditional.

           SELECT t.entry_id, 
                       t.title, 
                       t.url_title, 
                       d.field_id_13 AS event_lineup, 
                       d.field_id_14 AS event_details, 
                       d.field_id_15 AS event_day, 
                       d.field_id_16 AS event_flyer_front, 
                       d.field_id_17 AS event_flyer_back, 
                       d.field_id_18 AS event_facebook, 
                       d.field_id_12 AS event_date 
             FROM `exp_weblog_titles` AS t 
NATURAL JOIN `exp_weblog_data` AS d 
           WHERE d.weblog_id = 5 
               AND CAST(d.field_id_12 AS UNSIGNED) >= (unix_timestamp(Now())) 
      ORDER BY d.field_id_12 ASC

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久随 2024-09-18 11:33:52

我认为可能发生的情况是您的时间戳会根据时区进行调整,并且该调整在 CMS 和服务器上的配置不同。

What I think might be happening is your timestamps get adjusted for the time zone, and that adjustment is configured differently in the CMS and on the server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文