0

There are two variables,

$old_start = new DateTime("2020-12-13 14:20");
$old_end = new DateTime("2021-03-25 12:29");

Now take difference of those two dates:

$gap = $old_end->diff($old_start);

Consider third variable:

$new_start = new DateTime("2020-12-27 11:47");

and based upon this $new_start and $gap, I want a new variable $new_end that is something like add some time period in new starting date to obtain new ending date.

ADyson
  • 57,178
  • 14
  • 51
  • 63
krupal_m
  • 87
  • 8

1 Answers1

2

You can achieve that as following, you can learn more about the datetime manipulation from this How we can add two date intervals in PHP

$old_start = new DateTime("2020-12-13 14:20");
$old_end = new DateTime("2021-03-25 12:29");

$interval_diff = $old_start->diff($old_end);

$new_start = new DateTime("2020-12-27 11:47");

$new_end = $new_start->add($interval_diff);

print_r($interval_diff);
print_r($new_end);
Umer Abbas
  • 1,866
  • 3
  • 13
  • 19