Ad Code

Get current week date range using php

This PHP snippet will print current week date range (start week date and end week date). Week starting day will be Monday.


<?php

Method: 1
$monday = strtotime("last monday");
$monday = date('w', $monday)==date('w') ? $monday+7*86400 : $monday;

$sunday = strtotime(date("Y-m-d",$monday)." +6 days");


$this_week_sd = date("Y-m-d",$monday);

$this_week_ed = date("Y-m-d",$sunday);

echo "Current week range from $this_week_sd to $this_week_ed ";



Method: 2
$this_week_sd = date('Y-m-d',strtotime('last sunday +1 day'));
$this_week_ed = date('Y-m-d',strtotime('last sunday +7 day'));

?>

Post a Comment

0 Comments