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|
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 Coupon Found:
TOP-RATED CODING COURSES
Learn the skills of tomorrow
The best time to learn programming is now - follow this link to access 100+ coding courses and enjoy learning at a very low cost!