wpquery 在一个数组中:
'meta_query' => array(
array(
'key' => $metaKey,
// value should be array of (lower, higher) with BETWEEN
'value' => array('START_DATE', 'END_DATE'),
'compare' => 'BETWEEN',
'type' => 'DATE'
),
)
这是一个真实的 mysql 和 php 示例:
$db = getDB();
$sql = "SELECT
DATE(invoice_date) AS invoice_date,
COUNT(sage_allsalesbyproduct.id) AS row_count,
SUM(sage_allsalesbyproduct.qty) AS total_qty,
SUM(sage_allsalesbyproduct.gross) AS total_gross,
sage_allsalesbyproduct.productcode,
ItemGroup as item_group
FROM sage_allsalesbyproduct
left join stock s on s.ProductCode = sage_allsalesbyproduct.productcode
WHERE
invoice_date BETWEEN :fromdate AND :todate
GROUP BY productcode
order by total_qty desc";
$stmt = $db->prepare($sql);
$stmt->bindParam("fromdate", $fromdate, PDO::PARAM_STR);
$stmt->bindParam("todate", $todate, PDO::PARAM_STR);
$stmt->execute();
$feedData = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo json_encode($feedData);
记住 MySQL 使用 yyyy-mm-dd 格式来存储日期值。此格式是固定的,无法更改。
使用 mysql 你也可以做类似的事情
SELECT *
FROM order_details
WHERE order_date >= CAST('2014-02-01' AS DATE)
AND order_date <= CAST('2014-02-28' AS DATE);