简体   繁体   中英

PHP & strtotime headache

Here's my function

function thisProduction($week_start, $week_end, $this){
echo "<h2>Production > $this week (w/c ".$week_start." - ".$week_end.")</h2>";
}

Here's where I define the args

$this_week_start = date('Y-m-d',strtotime('this Monday'));
$this_week_end = date('Y-m-d',strtotime('this Sunday'));
$last_week_start = date('Y-m-d',strtotime('last Monday'));
$last_week_end = date('Y-m-d',strtotime('last Sunday'));

I call this will arguments as such

thisProduction($this_week_start, $this_week_end, 'This');
thisProduction($last_week_start, $last_week_end, 'Last');

I WANT (using todays date 31 Jan 2017 as example)

Production > This week (W/C 2017-01-30 - 2017-02-05)
Production > Last week (W/C 2017-01-23 - 2017-01-29)

Last night this was 'working' but today I get these results

PRODUCTION > THIS WEEK (W/C 2017-02-06 - 2017-02-05)
PRODUCTION > LAST WEEK (W/C 2017-01-30 - 2017-01-29)

Better use monday this week :

$this_week_start = date('Y-m-d',strtotime('monday this week'));
$this_week_end = date('Y-m-d',strtotime('sunday this week'));
$last_week_start = date('Y-m-d',strtotime('monday last week'));
$last_week_end = date('Y-m-d',strtotime('sunday last week'));

Result today and yesterday:

Production > This week (w/c 2017-01-30 - 2017-02-05)

Production > Last week (w/c 2017-01-23 - 2017-01-29)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM