如何按日期限制查询

我尝试将查询限制为仅显示过去 7 天(总是从星期五)的结果,即从上星期五 (12:01) 到当前星期五 (11:59)。我正在使用 woocommerce wp_wc_order_product_lookup 并希望准确显示该范围内的订单



慕容708150
浏览 67回答 1
1回答

德玛西亚99

这就是您获得 SQL Select 的方法。<?php&nbsp; &nbsp;&nbsp;$datetime1 = new DateTimeImmutable('last friday 12:00:00');$datetime2 = $datetime1->modify('+ 1 week');$sql = 'SELECT * wp_wc_order_product_lookup&nbsp; &nbsp; &nbsp; &nbsp; WHERE date_created BETWEEN&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ' . $datetime1->format("Y-m-d H:i:s")&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; . ' AND&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ' . $datetime2->format("Y-m-d H:i:s")&nbsp; &nbsp; ;echo $sql; // result: SELECT * table_name WHERE datetime_column_name BETWEEN 2020-04-10 12:00:00 AND 2020-04-17 12:00:00
打开App,查看更多内容
随时随地看视频慕课网APP