Add date in days until the specific day of the week arrives

0

I have a difficult task for you. I am developing a sales system for the company that I work for. Some customers require that tickets be issued due on specific days, eg:

The company Fulano LTDA demands that the ticket expire on a Wednesday.

It also has a paytable, Fulano LTDA company requires payments to be made every 21 days.

Let's say that the saleswoman made a sale today, she will generate a ticket with maturity for 21 days, 21 days will be July 23, ie it's a Monday, so what should happen is that these 21 days be postponed to "23" so that the maturity will arrive on a Wednesday. What I need is to check the customer's account for the day of the week in which he makes the payment, and that this payment is "pushed to the desired date", if he makes payments on Thursdays and the 21-day payment falls in the fourth, he pushes another day to fall on the fifth. I hope you understood me!

    
asked by anonymous 02.07.2018 / 19:13

1 answer

1

Use relative format .

First add the days:

$date = new \DateTime('+21 days');

This value will take you from the column of your database.

Then, change to the day of the week:

$date->modify('wednesday'));

The day of the week must be in English. So, a switch or a de/para table.

What can be simplified in:

$date = (new \DateTime('+21 days'))->modify('wednesday');

Working Code: link

    
02.07.2018 / 19:44