문제

I need help getting the "this week" full date range in the following format: Y-m-d

I have successfully been able to get "this month" full date range but not the "this week" full date range.

This is my code for "this month":

//Functions for later use
function firstOfMonth() {
    return date("Y-m-d", strtotime(date('m').'/01/'.date('Y').' 00:00:00'));
}

function lastOfMonth() {
    return date("Y-m-d", strtotime('-1 second',strtotime('+1 month',strtotime(date('m').'/01/'.date('Y').' 00:00:00'))));
}

//Setup the date_range variables
$date_start = firstOfMonth();
$date_end  = lastOfMonth();

Any help is greatly appreciated!

도움이 되었습니까?

해결책

Just so you know, your "first of month" code is wrong. If you're in August, it'll give you the range July 8th to August 7th. Use the correct d/m/Y format when doing it that way around.

As for the week, try this:

$start_week = strtotime("last monday midnight");
$end_week = strtotime("+1 week",$start_week);

$start_week = date("Y/m/d",$start_week);
$end_week = date("Y/m/d",$end_week);

다른 팁

Layton Everson you are correct. The correct format I think should be :

strtotime('-2  Monday');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top