“Split -Datum in Wochen PHP” Code-Antworten

Separates Datum von DateTime PHP

$time = new DateTime("2011-08-04 15:00:01");
$date = $time->format('n.j.Y');
$time = $time->format('H:i');
Akki batra

Separates Datum von DateTime PHP

date('Y-m-d', strtotime( '2015-04-16 15:00:01' ) );
Akki batra

Split -Datum in Wochen 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;
}
mukashwasti_

Ähnliche Antworten wie “Split -Datum in Wochen PHP”

Fragen ähnlich wie “Split -Datum in Wochen PHP”

Weitere verwandte Antworten zu “Split -Datum in Wochen PHP” auf PHP

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen