我需要从getdate()
星期一开始而不是星期日的“工作日”开始,有没有办法做到这一点?
这是我的代码,不用担心问题中的参数validatePlanningVendeur
是当我尝试获取当前日期时arret
,以便可以从星期一开始验证arret
。
您可能会注意到我写了$arret = $today["wday"]-1;
,这是我试图绕过wkday
Sunday = 0,以使Monday为0,但是现在它对星期日无效,因为它等于-1。
为了简短起见,现在$arret
仅在星期一至星期六工作。
function validatePlanningVendeur($week, $vendeur, $boutique, $type_connecte, $user_connecte){
$connexion = connexion();
// Getting the current date in order to get the end
$today = getdate();
$arret = $today["wday"]-1; // attempt to bypass sunday = 0
echo($arret);
// echo("Aujourdhui : " . $today["wday"]);
// echo("arret: " . $arret);
// We get every day of the week until today ($arret)
for($i = 0; $i <= $arret ; $i++){
// On crée le year-month-day pour chaque jour de la semaine
// echo($week[$i]);
$dateCurrent = getdate($week[$i]);
$day = $dateCurrent['mday'];
$month = $dateCurrent['mon'];
$year = $dateCurrent['year'];
// Used to fetch from DB
$jour = $year. '-' . $month . '-' . $day;
// echo("Jour : " . $jour . " ");
if($type_connecte == 1){ //Si c'est un RPV qui est connecté
// On assigne id_validation = 1
$request_validate = $connexion->prepare("UPDATE plannings SET id_validation = ? WHERE date_planning = ? AND id_employe = ? AND id_validation = ? AND id_boutique = ?");
$request_validate->execute(array(1, $jour, $vendeur, 0, $boutique));
}else{// On ne prend pas en compte la valeur boutique pour le RC
$request_validate = $connexion->prepare("UPDATE plannings SET id_validation = ? WHERE date_planning = ? AND id_employe = ? AND id_validation = ?");
$request_validate->execute(array(1, $jour, $vendeur, 0,));
}
}
}
尝试使用此:
$today = new DateTime();
// Get ordinal number of the day of the week by ISO 8601.
// It starts from 1 (Monday) to 7 (Sunday).
$arret = $today->format('N'); // Today is 7th day
for ($i = 0; $i <= $arret - 1 ; $i++) {
// do something
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句