Search
 
SCRIPT & CODE EXAMPLE
 

PHP

split date range into weeks php

//weeks
function getWeekRanges($start, $end)
{
    $timeStart = strtotime($start);
    $timeEnd = strtotime($end);
    $out = [];
    $milestones[] = $timeStart;
    $timeEndWeek = strtotime('next Monday', $timeStart);
    while ($timeEndWeek < $timeEnd) {
        $milestones[] = $timeEndWeek;
        $timeEndWeek = strtotime('+1 week', $timeEndWeek);
    }
    $milestones[] = $timeEnd;
    $count = count($milestones);
    for ($i = 1; $i < $count; $i++) {
        if ($i == $count - 1) {
            $out[] = [
                'start' => $milestones[$i - 1],
                'end' => $milestones[$i]
            ];
        } else {
            $out[] = [
                'start' => $milestones[$i - 1],
                'end' => $milestones[$i] - 1
            ];
        }
    }
    return $out;
}
//months
function getMonthRanges($start, $end)
{
	$timeStart = strtotime($start);
	$timeEnd   = strtotime($end);
	$out       = [];

	$milestones[] = $timeStart;
	$timeEndMonth = strtotime('first day of next month midnight', $timeStart);
	while ($timeEndMonth < $timeEnd) {
		$milestones[] = $timeEndMonth;
		$timeEndMonth = strtotime('+1 month', $timeEndMonth);
	}
	$milestones[] = $timeEnd;

	$count = count($milestones);
	for ($i = 1; $i < $count; $i++) {
		$out[] = [
			'start' => $milestones[$i - 1],
			'end'   => $milestones[$i] - 1
		];
	}

	return $out;
}
Comment

PREVIOUS NEXT
Code Example
Php :: laravel route group 
Php :: how to add custom navigation menus in wordpress themes 
Php :: laravel route limit parameter 
Php :: cors header ‘access-control-allow-origin’ missing IN PARTICULAR CAKEPHP API 
Php :: laravel guard 
Php :: install php56 with php73 catalina 
Php :: get current month laravel 
Php :: php website templates free download with database 
Php :: magento 2 laravel valet 502 bad gateway 
Php :: php 8 null safe operator 
Php :: PHP If If Else Else Statement 
Php :: laravel route regex except 
Php :: php nested class 
Php :: laravel delete method 
Php :: What is the name of scripting engine in PHP? 
Php :: hint extension in visual studio code for laravel 
Php :: pessimistic locking laravel 
Php :: Merge Two Collection 
Php :: jquery get data from php 
Php :: how to convert an array to uppercase before storing in database 
Php :: install laravel scout 
Php :: model not found laravel 
Php :: how to separate admin and user login in laravel 
Php :: laravel run command 
Php :: compress video file size php 
Php :: whats the difference between using date function and DATETime in php 
Php :: where is cache file in laravel 
Php :: laravel get data from database by id 
Php :: laravel gate 
Php :: Not Found The requested URL was not found on this server. Apache/2.4.46 (Win64) OpenSSL/1.1.1g PHP/7.4.11 Server at localhost Port 80 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =