Skip to content
Advertisement

How to show calendar month’s previous days?

I’m trying to make a calendar that shows this month, and then fills in the remaining days on the end rows with the dates from the next and previous months.

I managed to make it show next months dates and the thing is the issue is that I need it to show previous months dates as well.

If someone manages to figure out the issues please add what the problem was as well how you managed to fix it, to help me in the future.

I will add a image of the calendar as well.

Image

The script:

JavaScript

Advertisement

Answer

When you calculated $week_day_first, you can save your time calculated from the first day of the month into a variable.

JavaScript

Then you can reuse that later to calculate the offset of days before the first of the month.

JavaScript

Putting it all together:

JavaScript

Results in this output:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement