PHP | cal_from_jd() Function

The cal_from_jd() function is an inbuilt function in PHP which is used to convert a Julian Day Count into supported calendar such as Gregorian calendar, French Calendar, Jewish calendar etc. This function accepts two parameters $jd and $calendar and returns the array containing calendar information of the specified calendar.

Syntax:

array cal_from_jd( $jd, $calendar )

Parameters: This function accepts two parameters as mentioned above and described below:

  • $jd: It is used to specify the Julian day as integer.
  • $calendar: It is used to specify the calendar in which date converted. The supported calendars are Gregorian calendar, Julian calendar, French calendar and Jewish calendar.

Return Value: This function returns an array containing calendar information which are listed below:

  • date in form “month/day/year”
  • month
  • year
  • day of week
  • abbreviated and full names of weekday and month

Program 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// PHP program to implement cal_from_jd()
// and convert date to the CAL_GREGORIAN 
  
  
$input = unixtojd(mktime(0, 0, 0, 8, 16, 2016));
print_r(cal_from_jd($input, CAL_GREGORIAN));
?> 

chevron_right


Output:

Array
(
    [date] => 8/16/2016
    [month] => 8
    [day] => 16
    [year] => 2016
    [dow] => 2
    [abbrevdayname] => Tue
    [dayname] => Tuesday
    [abbrevmonth] => Aug
    [monthname] => August
)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// PHP program to implement cal_from_jd() 
// and convert date to the CAL_JEWISH calender
$today = unixtojd(mktime(0, 0, 0, 6, 20, 2007));
  
print_r(cal_from_jd($today, CAL_JEWISH));
?>

chevron_right


Output:

Array
(
    [date] => 11/4/5767
    [month] => 11
    [day] => 4
    [year] => 5767
    [dow] => 3
    [abbrevdayname] => Wed
    [dayname] => Wednesday
    [abbrevmonth] => Tammuz
    [monthname] => Tammuz
)

Related Articles:

Reference: http://php.net/manual/en/function.cal-from-jd.php

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.