imgrooot Posted April 6, 2017 Share Posted April 6, 2017 // find the time difference between now and the expiry date $expiry_date = '2017-04-20 09:02:23'; $then = new DateTime($expiry_date); $now = new DateTime(); $remaining_time = $then->diff($now); // I want to add two weeks to the new date. $two_weeks = $now->add(new DateInterval('P2W'))->format('Y-m-d H:i:s'); // new date that combines the remaining time from above and adds 2 weeks to create a new date. This is the issue here. How do I combine these two dates properly? The new date has to be in this format ('Y-m-d H:i:s') $new_date = $remaining_time + $two_weeks; Link to comment Share on other sites More sharing options...
requinix Posted April 6, 2017 Share Posted April 6, 2017 You want now + difference between now and then + two weeks? Isn't that the same as then + two weeks? Link to comment Share on other sites More sharing options...
imgrooot Posted April 6, 2017 Author Share Posted April 6, 2017 You want now + difference between now and then + two weeks? Isn't that the same as then + two weeks? Now that I think about it, I guess your right. Anyways I have solved the issue already. Here it is. // find the time difference between now and the expiry date $expiry_date = '2017-04-20 09:02:23'; $then = new DateTime($expiry_date); $now = new DateTime(); $remaining_days = $then->diff($now)->format("%a"); // I want to add two weeks to the new date. $current = new DateTime(); $two_weeks = new DateInterval('P2W'); $total_date = $current->add($two_weeks)->format('Y-m-d H:i:s'); // current date + 2 weeks + remaining days difference $dateTime = new DateTime($total_date); $new_date = $dateTime->modify('+'.$remaining_days.' days'); echo $new_date->format('Y-m-d H:i:s'); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.