gpt4 book ai didi

mysql查询选择昨天、今天和明天

转载 作者:行者123 更新时间:2023-11-29 00:36:21 24 4
gpt4 key购买 nike

我正在做一个项目,我必须从数据库中选择日期为昨天、今天和明天的所有条目。日期作为时间戳存储在数据库中。

到目前为止我有这个 PHP 代码

$hour = 12;
$today = strtotime("$hour:00:00");
$yesterday = strtotime('-1 day', $today);
$tomorrow = strtotime('+2 day', $today);
$today = get_date($today,"timestamp");

$result = $DB->query("SELECT product_id FROM " . DB_PREFIX . "expiry WHERE expiry_date BETWEEN $yesterday AND $tomorrow");

它不起作用。请帮忙。

最佳答案

试试这个

 $tomorrow = strtotime('+1 day', $today);

然后 sql 更改为这个

   BETWEEN '".$yesterday."' AND '".$tomorrow."'

并确保

   `" . DB_PREFIX . "expiry` 

不是那样的

  `" . DB_PREFIX . "_expiry`
^---------------did have this or something else like -

关于mysql查询选择昨天、今天和明天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14105479/

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