更新时间:2023-11-26 08:35:16
DATE_FORMAT()
返回字符串,而不是日期.将3个字符串参数传递给BETWEEN
...谁知道该返回什么.
DATE_FORMAT()
returns a string, not a date. Passing 3 string arguments to BETWEEN
... who knows what that is going to return.
要取消向后退代码,请使用:
To un-ass-backwards your code, use:
$week_start = date('Y-m-d',time()+( 1 - date('w'))*24*3600);
$week_end = date('Y-m-d',time()+( 7 - date('w'))*24*3600);
以mySQL期望的方式格式化日期,并且:
to format your dates in the way mySQL expects, and:
WHERE
start_date BETWEEN '".$week_start."' AND '".$week_end."'
在查询中.
或者,如果您更喜欢面向对象的方法,请执行以下操作:
Or if you would prefer an object-oriented approach, do something like this:
$week_start = new DateTime;
$week_end = new DateTime;
$week_start->setTimestamp(time()+( 1 - date('w'))*24*3600));
$week_end->setTimestamp(time()+( 7 - date('w'))*24*3600);
然后在您的查询中执行
WHERE
start_date
BETWEEN '".$week_start->format('Y-m-d')."'
AND '".$week_end->format('Y-m-d')."'
然后,对于其他所有内容,您都可以按照自己的意愿来回显该格式:
Then for everything else, you can echo the format how you wish:
echo $date->format('d-m-Y'); // etc