Link to home
Avatar of Jazzy 1012
Jazzy 1012

asked on

Php logic to add to date card

Is there a php logic where if today is thursday 23rd, it will display monday 27, tuesday 28, wednesday 29  thursday 30

And if today is friday 24th , it will display monday 3rd, tuesday 4th, wed 5th, thursday 6th.

Also is there a way to display these days as the day and date (how it is shown above).
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Yes, the DateTime object has the ability to perform "date math" (add days, etc...). Check out this article for a good explanation of how it works, along with some examples:
https://www.experts-exchange.com/articles/20920/Handling-Time-and-Date-in-PHP-and-MySQL-OOP-Version.html
What rules would you use to decide whether you want "next week" like 23rd --> 27th versus "two weeks" like 24th --> 3rd?
Avatar of Jazzy 1012
Jazzy 1012

ASKER

The rules are that if the date is monday-thursday, then it goes from 23rd-27th (this week to next week), But if the day is from friday-sunday it goes from 24th-3rd (next week to after)
Thanks.  So today is Wednesday, March 22, and the output should be what, exactly?
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
It is kind of how I want it but this is the output I want:

For example, today is Monday 20th - the Thursday the 23rd, so the next available date will be Tuesday the 4th.
So my output should be:
<input type="checkbox" class="colour-button1" value="10 - 12" id="btn1" disabled/><label for="btn1" style="position:relative;"><i class="fa fa-check-circle fa-lg hide11" id="chk-btn1"></i>   Tuesday, March 28</label>
<br><br>
<input type="checkbox" class="colour-button1" value="10 - 12" id="btn2" disabled /><label for="btn2" class="labe1" style="position:relative;"><i class="fa fa-check-circle fa-lg hide11" id="chk-btn2"></i>  Thursday,March 30th</label>
<br><br>
<input type="checkbox" class="colour-button1" value="10 - 12" id="btn3" disabled/><label for="btn3" style="position:relative;"><i class="fa fa-check-circle fa-lg hide11" id="chk-btn3"></i>  Tuesday, April 4th</label>
<br><br>
<input type="checkbox" class="colour-button1" value="10 - 12" id="btn4" disabled/><label for="btn4" class="labe1" style="position:relative;"><i class="fa fa-check-circle fa-lg hide11" id="chk-btn4"></i>  Thursday, April 6th</label>

Open in new window


If it is Friday the 24th- Sunday the 26th, the next available date is Tuesday April 4th

<input type="checkbox" class="colour-button1" value="10 - 12" id="btn1" disabled/><label for="btn1" style="position:relative;"><i class="fa fa-check-circle fa-lg hide11" id="chk-btn1"></i>   Tuesday, April 4th</label>
<br><br>
<input type="checkbox" class="colour-button1" value="10 - 12" id="btn2" disabled /><label for="btn2" class="labe1" style="position:relative;"><i class="fa fa-check-circle fa-lg hide11" id="chk-btn2"></i>  Thursday, April 6th</label>
<br><br>
<input type="checkbox" class="colour-button1" value="10 - 12" id="btn3" disabled/><label for="btn3" style="position:relative;"><i class="fa fa-check-circle fa-lg hide11" id="chk-btn3"></i>  Tuesday, April 11th</label>
<br><br>
<input type="checkbox" class="colour-button1" value="10 - 12" id="btn4" disabled/><label for="btn4" class="labe1" style="position:relative;"><i class="fa fa-check-circle fa-lg hide11" id="chk-btn4"></i>  Thursday, April 13th</label>

Open in new window

Sorry, I'm not following the logic of what you're trying to create.  Maybe just give us a table of weekdays and expected outputs?  Or if it's not driven by weekdays, maybe a table of the days of the month and the expected outputs.
I just added a few more days to the weeks and this worked perfectly, thanks!
Great! :-)