Subtraction of periods, how to implement?

Good day!

Have a question, don't know how to solve it.
Let's say we have three periods.

  1. with 2017-11-06 on 2017-11-20
  2. with 2017-11-10 for 2017-11-19 (status: false)
  3. with 2017-11-14 for 2017-11-25


How to subtract a period for the number 2, which would output to

  1. with 2017-11-06 on 2017-11-10
  2. with 2017-11-20 for 2017-11-25


Use the datetime object.
# Where 
$period->getDate()->getFirstDate() //2017-11-06T00:00:00
# and, accordingly 
$period->getDate()->getLastDate() //2017-11-20T00:00:00
# if status is false, then it should be deducted.
$period->getDate()->getStatus() //2017-11-20T00:00:00


Thank you.
June 26th 19 at 14:13
1 answer
June 26th 19 at 14:15
Subtraction (A - B) is reduced to four options:
1. A->firstDate >= B->firstDate && A->lastDate <= B->lastDate
Completely removed the period A.

2. A->firstDate > B->firstDate && A->lastDate > B->lastDate
A->firstDate := B->lastDate

3. A->firstDate < B->firstDate && A->lastDate < B->lastDate
A->lastDate := B->firstBade

4. A->firstDate < B->firstDate && A->lastDate > B->lastDate
The period a is replaced by two new ones:
A1->firstDate := A->firstDate, A1->lastDate := B->firstDate
A2->firstDate := B->lastDate, A2->lastDate := A->lastDate
Thanks, will try. - Elvera.Muraz commented on June 26th 19 at 14:18

Find more questions by tags Work with date / timePHP