PHP: Identify date of last and next Monday
Question by Axuter | 2012-03-13 at 23:40
I need a function in PHP, that outputs the date of the last and the next Monday. I was thinking something about that topic, but I had no idea, because I do not know how to determine a weekday in PHP. The whole seems to be quite complicated, as my previous research on the Internet has shown. I found some huge and long calendar calculations, which I find a bit too long for the problem.
Has anyone of you a simple approach and can help me?
Related Topics
PHP: Current Date and Time
Tutorial | 0 Comments
PHP: Determine Week Number
Tutorial | 0 Comments
MySQL: Write current Date or Time into Column
Tutorial | 0 Comments
JavaScript: Get current Date and Time
Tutorial | 1 Comment
Rosenmontag: Dates 2025, 2024, 2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015 and 2014
Info | 0 Comments
Rose Monday: The earliest and latest date possible
Question | 1 Answer
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
Fortunately, PHP already comes by itself with all that we need to solve the problem. For this purpose, here is the code:
We can simply pass the parameter "last Monday" or "next Monday" to the PHP function strtotime() and it gives us the date we have searched for. The lines below output the date for us.
If you need a different day, you can simply use the names of the weekdays and already you got it!
Similarly, we can also operate in the same way with using "last week" or "next week", "month" or "year", to get the date of the last week, the last months or year.
2012-03-15 at 16:47