Add date in days until specific day of the week

Asked

Viewed 100 times

0

I have a mission for you. I am developing a sales system for the company I work for. Some customers require billets to be issued maturing on specific days, Ex:

The company Fulano LTDA requires that the ticket wins on a Wednesday.

Also has a salary schedule, the company Fulano LTDA requires that payments are 21 in 21 days.

Let’s say the seller made a sale today, it will generate a ticket due for 21 days, from here 21 days will be day 23/07, IE, It is a Monday, so what should happen is that these 21 days are postponed in "23" so that the maturity reaches a Wednesday. What I need is to check the customer’s registration which day of the week in which he performs the payment, and that this salary is "pushed to the desired date", if he makes payments on Thursdays and the maturity 21 days fall on Wednesday, he pushes another day to fall on the farm. I hope you understand me!

1 answer

1


Use relative format.

First add the days:

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

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

Then change to the day of the week:

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

The day of the week needs to be in English. Soon, a switch or a table de/para.

What can be simplified in:

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

Code in operation: https://3v4l.org/ALDbJ

  • Man, I took my hat off to you, thank you very much!!!!!

  • Just one more question, friend, and if I already have a date and want to add to it the days, for example, instead of taking today’s date and add the 21 days and postpone to Wednesday, I take tomorrow’s date and add.... how would you look?

  • @Nicholasruschelkrüger practically the same way, only the parameters change, examples here at this link: https://3v4l.org/ivVjN

Browser other questions tagged

You are not signed in. Login or sign up in order to post.