토요일을 주 시작일 (토요일-> 금요일)로 기준으로 주 번호를 어떻게 찾습니까? 나는 이것을 알아내는 데 지나치게 많은 어려움을 겪었습니다. PHP 솔루션이 있으면 좋겠지 만, 어떤 언어로든 어떤 예도 가능합니다.
우리 회사의 주당 근무 시간은 토요일 (1 일)부터 금요일 (7 일)까지입니다. 주 번호를 표시 할 수 있어야합니다 (52/53의 23 주). 혼란 스러울 수 있고 정상적인 Date('W', $time)
기능에서 주어지는 주 번호 로 충분하지만 의심 스럽습니다.
Excel에서 가능한 솔루션을 찾았지만 VBA를 정말 오랫동안 수행하지 않았으며이 구현의 앞뒤를 만들 수 없습니다 .
이 기능은 내 문제를 해결하는 것처럼 보이지만 더 먼 해의 테스트가 필요할 수도 있습니다.
// The N option gives the normal week day, arithmetic makes it return my custom week days
function getDayOfWeek(\DateTimeImmutable $date)
{
return ($date->format('N') + 2) % 7;
}
function getWeekNumber(\DatetimeImmutable $date)
{
// Recursive function that loops through every day until it gets the start of a week
$startOfWeek = function (\DateTimeImmutable $date) use (&$startOfWeek) {
return (getDaysOfWeek($date) === 1)
? $date : $startOfWeek($date->modify('+1 day'));
};
// The z option tells us what day of the year this is,
// not a 100% sure this step is necessary
if (getDayOfWeek($date === 1) {
$nbDays = $date->format('z');
else {
$nbDays = $startOfWeek($date->modify('-7 days'))->format('z');
}
// Divides by the number of days in a week to get the number of weeks
return ceil($nbDays / 7);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다