Fri, 17 May 2024


PHP Calendar Function

By: Peter, NetArt Media
Wed, 1 August 2018
PHP Calendar Function

The PHP date and time functions suit me just fine as web developer, doing everything I need for returning related date and time information. However, that doesn't mean that I'm closed when it comes to other ideas. I do try to cover most things PHP related on this site and the 'calendar' function may come in handy for some of you.

For our purposes, we will use the 'Cal_Julian' constant. We could also use 'Cal_Gregorian', but I thought I would keep things consistent throughout this short article. Before I present the first example though, here is a full list of the constants that can be used with the 'calendar' function.

CAL_GREGORIAN - Gregorian calendar
CAL_JULIAN - Julian calendar
CAL_JEWISH - Jewish calendar
CAL_FRENCH - French Republican calendar
CAL_NUM_CALS
CAL_DOW_DAYNO
CAL_DOW_SHORT
CAL_DOW_LONG
CAL_MONTH_GREGORIAN_SHORT
CAL_MONTH_GREGORIAN_LONG
CAL_MONTH_JULIAN_SHORT
CAL_MONTH_JULIAN_LONG
CAL_MONTH_JEWISH
CAL_MONTH_FRENCH
CAL_EASTER_DEFAULT
CAL_EASTER_DEFAULT
CAL_EASTER_ROMAN
CAL_EASTER_ALWAYS_GREGORIAN
CAL_EASTER_ALWAYS_JULIA
CAL_JEWISH_ADD_ALAFIM_GERESH
CAL_JEWISH_ADD_ALAFIM
CAL_JEWISH_ADD_GERESHAYIM

A Google search will provide you with more information on each of the above constants.

Our first example displays the amount of days in a defined month back in 2003.


This is quite self-explanatory. The result is '31' days.

Now we will convert 'calendar' to 'jd', which represents Julian Day.


The offset '1' represents the mode of return. Here is a list of the different modes that can be used.

0 − Gregorian - abbreviated (Jan, Feb, Mar, etc.)
1 − Gregorian (January, February, March, etc.)
2 − Julian - abbreviated (Jan, Feb, Mar, etc.)
3 − Julian (January, February, March, etc.)
4 − Jewish (Tishri, Heshvan, Kislev, etc.)
5 − French Republican (Vendemiaire, Brumaire, Frimaire, etc.)

The next example returns the day of the week. The result I see is one day ahead of my time, but this is probably because the day I am seeing is several hours ahead. As you can see, we once again use the mode offset. I used '1' again for this example.



As I mentioned earlier, the PHP calendar function may not be something you would use all the time, but it could provide an alternative here and there for the date and time functions.

Perhaps this can be helpful to you some day.


Category: Web Development
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox