george
george

Reputation: 15

strtotime display 01.01.1970 as result after new year change

I'm using strtotime to display the date 'd.m.Y' for next week's tuesday to friday. In 2017 everything went fine, but since 2018 I get the 01.01.1970 as result. Can´t find the the problem. Here the code:

<?php
date_default_timezone_set('UTC');
$week = date('W');
$yearnow = date('Y');
$nextweek = date('W')+1;

$timestamp_tu = strtotime("{$yearnow}-W{$nextweek}-2");
$date_tu = date('d.m.Y', $timestamp_tu);
$timestamp_we = strtotime("{$yearnow}-W{$nextweek}-3");
$date_we = date('d.m.Y', $timestamp_we);
$timestamp_th = strtotime("{$yearnow}-W{$nextweek}-4");
$date_th = date('d.m.Y', $timestamp_th);
$timestamp_fr = strtotime("{$yearnow}-W{$nextweek}-5");
$date_fr = date('d.m.Y', $timestamp_fr);

?>

But if I use actual $week instead of $nextweek the shown date is correct. Thank you.

Upvotes: 0

Views: 58

Answers (1)

Ben
Ben

Reputation: 5129

You can simply achieve by this:

date('d.m.Y', strtotime('next week tuesday'));
date('d.m.Y', strtotime('next week wednesday'));
date('d.m.Y', strtotime('next week thurday'));
date('d.m.Y', strtotime('next week friday'));

Upvotes: 1

Related Questions