Pergunta

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!

Foi útil?

Solução

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);

Outras dicas

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

strtotime('-2  Monday');
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top