以下代码用于查找自定义wordpress查询之前的下一个3周的第5天(周五)和第6天(周六)。出于某种原因,我无法让它增加第6天。
有什么想法吗?
/* We need this to start on a Friday */
$datDate = date( 'Y-m-d' );
while( date('w', strtotime( $datDate ) ) != 5 ) {
$datDate = date( 'Y-m-d', strtotime( $datDate . " +1 DAY" ) );
}
/* This is over 3 weeks, so we need 3 arrays of all available days */
$arrDate1[] = "'".$datDate . " 00:00:00'";
for( $i = 1; $i < 7; $i++ ) {
$datDate = date( 'Y-m-d', strtotime( $datDate . " +1 DAY" ) );
$arrDate1[] = "'".$datDate ." 00:00:00'";
}
/* Ok, create a new array and add another 7 days */
for( $i = 1; $i <= 7; $i++ ) {
$datDate = date( 'Y-m-d', strtotime( $datDate . " +1 DAY" ) );
$arrDate2[] = "'".$datDate . " 00:00:00'";
}
/* Same again for our third array */
for( $i = 1; $i <= 7; $i++ ) {
$datDate = date( 'Y-m-d', strtotime( $datDate . " +1 DAY" ) );
$arrDate3[] = "'".$datDate . " 00:00:00'";
}
/* Convert our 3 dates to comma seperates strings for the IN QUERY */
$strDate1 = implode(",",$arrDate1);
$strDate2 = implode(",",$arrDate2);
$strDate3 = implode(",",$arrDate3);
$strQuery = "
答案 0 :(得分:0)
您的第一个循环缺少=
中的<=
:
for( $i = 1; $i < 7; $i++ ) {
应该是
for( $i = 1; $i <= 7; $i++ ) {
这是你的意思吗?