Good day!

Have a question, don't know how to solve it.

Let's say we have three periods.

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

Use the datetime object.

Thank you.

Have a question, don't know how to solve it.

Let's say we have three periods.

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

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

- with 2017-11-06 on 2017-11-10
- 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.

asked June 26th 19 at 14:13

1 answer

answered on 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

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