У меня есть простой фрагмент кода для сравнения дат и подсчета продуктов, он работает для всех моих месяцев, кроме августа и сентября. Я прошел через это дюжину раз, все выглядит одинаково для всех месяцев, но даты августа и сентября не найдены, другие даты проверены.
Извините за хромой код, я еще новичок.
заранее спасибо
<?php
//$ship_date = 20170420;
//$ship_date = 20170520;
//$ship_date = 20170620;
//$ship_date = 20170720;
//$ship_date = 20170820;
//$ship_date = 20170920;
//$ship_date = 20171020;
//$ship_date = 20171120;
$ship_date = 20171220;
$apr = '1';
$may = '1';
$june = '1';
$july = '1';
$august = '1';
$september = '1';
$october = '1';
$nov = '1';
$decem = '1';
$valid = "Y";
$case_qty = 1;
$apr_start = 20170401;
$apr_end = 20170430;
$may_start = 20170501;
$may_end = 20170531;
$june_start = 20170601;
$june_end = 20170630;
$july_start = 20170701;
$july_end = 20170731;
$augmonth_start = 20170801;
$augmonth_stop = 20170831;
$september_start = 20170901;
$september_stop = 20170930;
$october_start = 20171001;
$october_end = 20171031;
$nov_start = 20171101;
$nov_end = 20171131;
$decem_start = 20171201;
$decem_end = 20171231;
$jan_start = 20180101;
$jan_end = 20180131;
$feb_start = 20180201;
$feb_end = 20180228;
$mar_start = 20180301;
$mar_end = 20180331;
if ($valid == "Y")
{
if (($ship_date >= $apr_start) && ($ship_date <= $apr_end))
{
echo "Sold apr<br />";
$apr = $apr + $case_qty;
$jan = 0;
$feb = 0;
$mar = 0;
//$apr = 0;
$may = 0;
$june = 0;
$july = 0;
$august = 0;
$september = 0;
$october = 0;
$nov = 0;
$decem = 0;
} elseif (($ship_date >= $may_start) && ($ship_date <= $may_end))
{
echo "Sold may<br />";
$may = $may + $case_qty;
$jan = 0;
$feb = 0;
$mar = 0;
$apr = 0;
//$may = 0;
$june = 0;
$july = 0;
$august = 0;
$september = 0;
$october = 0;
$nov = 0;
$decem = 0;
} elseif (($ship_date >= $june_start) && ($ship_date <= $june_end))
{
echo "Sold june<br />";
$june = $june + $case_qty;
$jan = 0;
$feb = 0;
$mar = 0;
$apr = 0;
$may = 0;
//$june = 0;
$july = 0;
$august = 0;
$september = 0;
$october = 0;
$nov = 0;
$decem = 0;
} elseif (($ship_date >= $july_start) && ($ship_date <= $july_end))
{
echo "Sold july<br />";
$july = $july + $case_qty;
$jan = 0;
$feb = 0;
$mar = 0;
$apr = 0;
$may = 0;
$june = 0;
//$july = 0;
$august = 0;
$september = 0;
$october = 0;
$nov = 0;
$decem = 0;
} elseif (($ship_date >= $augmonth_start) && ($ship_date <= $augmonth_end))
{
echo "Sold august <br />";
$august = $august + $case_qty;
$jan = 0;
$feb = 0;
$mar = 0;
$apr = 0;
$may = 0;
$june = 0;
$july = 0;
$september = 0;
$october = 0;
$nov = 0;
$decem = 0;
} elseif (($ship_date >= $september_start) && ($ship_date <= $september_end))
{
echo "Sold sept <br />";
$september = $september + $case_qty;
$jan = 0;
$feb = 0;
$mar = 0;
$apr = 0;
$may = 0;
$june = 0;
$july = 0;
$august = 0;
$october = 0;
$nov = 0;
$decem = 0;
} elseif (($ship_date >= $october_start) && ($ship_date <= $october_end))
{
echo "Sold oct<br />";
$may = $october + $case_qty;
$jan = 0;
$feb = 0;
$mar = 0;
$apr = 0;
$may = 0;
$june = 0;
$july = 0;
$august = 0;
$september = 0;
//$october = 0;
$nov = 0;
$decem = 0;
} elseif (($ship_date >= $nov_start) && ($ship_date <= $nov_end))
{
echo "Sold nov<br />";
$nov = $nov + $case_qty;
$jan = 0;
$feb = 0;
$mar = 0;
$apr = 0;
$may = 0;
$june = 0;
$july = 0;
$august = 0;
$september = 0;
$october = 0;
//$nov = 0;
$decem = 0;
} elseif (($ship_date >= $decem_start) && ($ship_date <= $decem_end))
{
echo "Sold decem<br />";
$decem = $decem + $case_qty;
$jan = 0;
$feb = 0;
$mar = 0;
$apr = 0;
$may = 0;
$june = 0;
$july = 0;
$august = 0;
$september = 0;
$october = 0;
$nov = 0;
//$decem = 0;
} elseif (($ship_date >= $jan_start) && ($ship_date <= $jan_end))
{
echo "Sold jan<br />";
$jan = $jan + $case_qty;
//$jan = 0;
$feb = 0;
$mar = 0;
$apr = 0;
$may = 0;
$june = 0;
$july = 0;
$august = 0;
$september = 0;
$october = 0;
$nov = 0;
$decem = 0;
} elseif (($ship_date >= $feb_start) && ($ship_date <= $feb_end))
{
echo "Sold feb<br />";
$feb = $feb + $case_qty;
$jan = 0;
//$feb = 0;
$mar = 0;
$apr = 0;
$may = 0;
$june = 0;
$july = 0;
$august = 0;
$september = 0;
$october = 0;
$nov = 0;
$decem = 0;
} elseif (($ship_date >= $mar_start) && ($ship_date <= $mar_end))
{
echo "Sold mar<br />";
$mar = $mar + $case_qty;
$jan = 0;
$feb = 0;
//$mar = 0;
$apr = 0;
$may = 0;
$june = 0;
$july = 0;
$august = 0;
$september = 0;
$october = 0;
$nov = 0;
$decem = 0;
} else
{
echo "No month selected!!!!!! " . $ship_date . "<br />";
$jan = 0;
$feb = 0;
$mar = 0;
$apr = 0;
$may = 0;
$june = 0;
$july = 0;
$august = 0;
$september = 0;
$october = 0;
$nov = 0;
$decem = 0;}
}
echo "Month Totals: " . $jan . " " . $feb . " " . $mar . " " . $apr . " " . $may . " " . $june . " " . $july .
" " . $august . " " . $september . " " . $october . " " . $nov . " " . $decem . "<br />";
?>
У вас есть эти переменные:
$augmonth_stop = 20170831;
$september_stop = 20170930;
Но проверяем что-то другое:
($ship_date <= $augmonth_end)
($ship_date <= $september_end)
Исправьте одно или другое, и ваш код должен работать.
Тем не менее, посмотрите на использование некоторой встроенной функции даты PHP, как strtotime()
или, что еще лучше для вашего приложения, DateTime
учебный класс.
Других решений пока нет …