People live in different time zones and use different calendars. It is useful to stay aware of those inconsistencies when you're making a website or application as well. Using the PHP calendar feature, a need to switch from one to another might sometimes arise.
There is a whole bunch of designated functions and constants for calendars PHP supports. All you need to do is compile it with a --enable-calendar extension.
In this PHP calendar tutorial, you will find an extensive list of functions and predefined constants that you can use, complete with descriptions and versions of PHP in which they were first introduced.
PHP Calendar: Main Tips
- PHP calendar code functions simplify different calendar conversion.
- They are based on the Julian Day Count, starting at January 1st, 4713 B.C.
- To convert to any other calendar precisely, convert to Julian Day Count, then to the calendar format of your choice.
- Keep in mind that Julian Day Count and Julian Calendar are two different things!
Functions to Apply
The following table includes the majority of functions that can be applied to the PHP calendar:
|cal_days_in_month()||Return number of days in month for specified year and calendar|
|cal_from_jd()||Convert Julian Day Count into date of specified calendar|
|cal_info()||Return information about specified calendar PHP is using|
|cal_to_jd()||Convert date in specified calendar to Julian Day Count format|
|easter_date()||Return Unix timestamp for midnight on Easter of specified year|
|easter_days()||Return number of days between March 21st and the Easter Day in a specified year|
|frenchtojd()||Convert French Republican date to Julian Day Count format|
|gregoriantojd()||Convert Gregorian date to Julian Day Count format|
|jddayofweek()||Return day of week|
|jdmonthname()||Return month name|
|jdtofrench()||Convert Julian Day Count to French Republican date|
|jdtogregorian()||Convert Julian Day Count to Gregorian date|
|jdtojewish()||Convert Julian Day Count to Jewish date|
|jdtojulian()||Convert Julian Day Count to Julian date|
|jdtounix()||Convert Julian Day Count to Unix timestamp|
|jewishtojd()||Convert Jewish date to Julian Day Count format|
|juliantojd()||Convert Julian date to Julian Day Count format|
|unixtojd()||Convert Unix timestamp to Julian Day Count format|
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid certificates of completion
- Professional service
- Flexible timetables
- A variety of features to choose from
- Professional certificates of completion
- University-level courses
- Multiple Online degree programs
- Great user experience
- Offers quality content
- Very transparent with their pricing
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
PHP constants have a lot in common with variables. The main differences are that predefined constants cannot be modified or redefined. For more information on this topic, visit this tutorial.
|CAL_GREGORIAN||Int||PHP 4 and newer|
|CAL_JULIAN||Int||PHP 4 and newer|
|CAL_JEWISH||Int||PHP 4 and newer|
|CAL_FRENCH||Int||PHP 4 and newer|
|CAL_NUM_CALS||Int||PHP 4 and newer|
|CAL_DOW_DAYNO||Int||PHP 4 and newer|
|CAL_DOW_SHORT||Int||PHP 4 and newer|
|CAL_DOW_LONG||Int||PHP 4 and newer|
|CAL_MONTH_GREGORIAN_SHORT||Int||PHP 4 and newer|
|CAL_MONTH_GREGORIAN_LONG||Int||PHP 4 and newer|
|CAL_MONTH_JULIAN_SHORT||Int||PHP 4 and newer|
|CAL_MONTH_JULIAN_LONG||Int||PHP 4 and newer|
|CAL_MONTH_JEWISH||Int||PHP 4 and newer|
|CAL_MONTH_FRENCH||Int||PHP 4 and newer|
|CAL_EASTER_DEFAULT||Int||PHP 4.3 and newer|
|CAL_EASTER_ROMAN||Int||PHP 4.3 and newer|
|CAL_EASTER_ALWAYS_GREGORIAN||Int||PHP 4.3 and newer|
|CAL_EASTER_ALWAYS_JULIAN||Int||PHP 4.3 and newer|
|CAL_JEWISH_ADD_ALAFIM_GERESH||Int||PHP 5.0 and newer|
|CAL_JEWISH_ADD_ALAFIM||Int||PHP 5.0 and newer|
|CAL_JEWISH_ADD_GERESHAYIM||Int||PHP 5.0 and newer|
PHP Calendar: Summary
- Calendar PHP functions are used to easily convert between different calendars.
- When converting from one calendar to another, you must first convert to the Julian Day Count and only then choose the format you prefer to use from now on. Julian Day Count starts on January 1st, 4713 B.C. and is a completely different thing from the Julian Calendar - don't mix those up!
- PHP has to be compiled with --enable-calendar option to support calendar functions.
Latest Udacity Coupon Found:
75% OFF COURSES
Udacity Black Friday Offer
The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!