0

I have a series of multiple different dates and I want to change them all by the same number. I only know the new date value of the first of the dates.

If I wanted to increase them all by the same value, I thought id just substract the current date from the new date to get the Time difference and add that to all the other dates. How would i go about doing that? I know the add function but this is done using a DateInterval, which i have no idea to create out of a date.

Example: i have the dates 2016-01-19 00:00, 2016-02-19 00:00, 2016-02-19 00:00 and i know the first one has to get changed to 2016-01-20 00:00. Based on the difference between them i want to calculate how much i have to increase the other 2 dates by.

So basically

$Interval = strtotime(16-01-20 00:00) - strtotime(16-01-19 00:00);

$newTime = strtotime(16-02-19 00:00) + $Interval;

I solved the problem now, which was that i had put the $Interval in a strtotime aswell. I overread that completely, thinking it wasn't the cause of the error

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
NMLcygni
  • 61
  • 1
  • 7

1 Answers1

0

Try this code. may help you.

<?php
   $datetime1 = new DateTime('2009-10-11');
   $datetime2 = new DateTime('2009-10-19');
   $interval = $datetime1->diff($datetime2);
   echo $interval->format('%R%a days');

   $datetime3 = "2010-09-17";
   echo $newthirddata = date('Y-m-d', strtotime($datetime3. $interval->format('%R%a days')));
   ?>
Makwana Ketan
  • 1,380
  • 1
  • 14
  • 22