-1

Without knowing or using any kind of date, what's the best way to just add 1 day to the day of the week?

For example, I have Monday and I want to add +1 Days. Something like this

echo ('Monday + 1 days');

I tried with date(); but couldn't find a solution. Any ideas?

moo moo
  • 476
  • 5
  • 20

2 Answers2

5

You can simply do:

<?php
    echo date('l', strtotime('Monday + 1 day'));

We just use the strtotime logic of adding a time period and wrap it in a date format of l - which is full text representation of the day.

l (lowercase 'L') A full textual representation of the day of the week Sunday through Saturday

refs:

https://secure.php.net/manual/en/function.strtotime.php

https://secure.php.net/manual/en/function.date.php

treyBake
  • 6,440
  • 6
  • 26
  • 57
  • 1
    There is no reason to answer a question that has been answered thousands of times. – Andreas Mar 19 '19 at 11:55
  • @Andreas maybe, linked dupe uses a date - not necessarily a day. In that way tis different - but I guess it is more or less same principle - happy to rm if wanted? – treyBake Mar 19 '19 at 11:57
  • Thank you so much :) I really did check a dozen other answers before asking but the others all used dates and I really couldn't figure it out. This really helped me and hopefully someone else too. – moo moo Mar 19 '19 at 11:58
  • The duplicate uses strtotime and date. Nothing new. Visiting the manual about the two functions should be done prior to posting a question in my opinion. YMMV. – Andreas Mar 19 '19 at 12:00
  • @Andreas what does YMMV mean? haha #acronymscrub - but deleting my answer seems a good way to go then :) – treyBake Mar 19 '19 at 12:07
  • Your mileage may vary. Meaning you may have a different opinion or reality. It comes from the car industry where they can say a car can drive x miles on a tank, and they add YMMV. Because if it's uphill or city or someone always driving in first gear. – Andreas Mar 19 '19 at 12:09
  • @Andreas ahh learn something new! Well, the principle is the same, so dupe away :) will rm in <5 mins – treyBake Mar 19 '19 at 12:10
  • I don't think you can. It's accepted with +5. – Andreas Mar 19 '19 at 12:11
  • @Andreas damn, sorry :/ – treyBake Mar 19 '19 at 12:13
2

There is no built-in function in PHP that says "the day after Monday is Tuesday" without referring to a particular Monday (which is what strtotime would do). Of course, you may choose to not care that they refer to a particular Monday and Tuesday, since the pattern hasn't changed recently and will not change in the foreseeable future.

You can use an if statement or a switch-case statement. You can even make it work in a different language.

if ($date === "lundi") return "mardi";
if ($date === "mardi") return "mercredi";
// etc
Joni
  • 108,737
  • 14
  • 143
  • 193