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

时间:2022-10-01 09:27:43

I'm working on a project where I must select from database all entries which dates are yesterday, today, and tomorrow. The dates are stored in the database as timestamp.

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

I have this PHP codes so far

到目前为止,我有这个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");

It's not working. please help.

这不是工作。请帮助。

1 个解决方案

#1


1  

try this

试试这个

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

and th sql change to this

这是第一个sql变化。

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

and make sure that

并确保

   `" . DB_PREFIX . "expiry` 

is not like that

不是这样

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

#1


1  

try this

试试这个

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

and th sql change to this

这是第一个sql变化。

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

and make sure that

并确保

   `" . DB_PREFIX . "expiry` 

is not like that

不是这样

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