How to find the number of days between two days not dates using PHP?
I know how to get the number of days between two dates, but my input values are day names (date-ignorant).
Inputs/Outputs:
Wednesday
and Saturday
returns 3
Sunday
and Wednesday
returns 3
Your task doesn't seem to require date functions at all. A simple lookup array will suffice.
Code: (Demo)
Output:
Or you can replace the lookup array with 4 function calls and achieve the same outcome: (Demo)
Use the PHP
date_diff()
function (docs).Per the clarification, you could create arbitrary Saturdays and Wednesdays to calculate it:
Would return "3", but depending when you ran it.
You can write the name of the day for parsing in a new DateTime class:
Also below the one line version: