Search code examples
phpdatetimestrtotime

php strtotime "last monday" if today is monday?


I want to use strtotime("last Monday").

The thing is, if today IS MONDAY, what does it return? It seems to be returning the date for the monday of last week. How can I make it return today's date in that case?


Solution

  • How can I make it return today's date in that case?

    pseudocode:

    if (today == monday)
        return today;
    else
        return strtotime(...);
    

    Btw, this trick also could work:

    strtotime('last monday', strtotime('tomorrow'));