Open In App
Related Articles

PHP | gregoriantojd() Function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
The gregoriantojd() function is a built-in function which converts a Gregorian date to a Julian Day Count. The function accepts three parameters in format $month / $day / $year, which represents the date in Gregorian calendar and converts it to a Julian Day count. Syntax:
gregoriantojd( $month, $day, $year) 
Parameters: The function accepts three mandatory parameters as shown above and described below:
  1. $month – This parameter specifies the month number in Gregorian calendar. The month number is in range 1-12 inclusive. If a month number in excess of 12 or less than 0 is passed, the Julian day is returned as 0.
  2. $day – This parameter specifies the day in Gregorian calendar. The day number is in range 1-31 inclusive. If a day number in excess of 31 or less than 0 is passed, the Julian day is returned as 0. Leap years are not taken into consideration
  3. $year – This parameter specifies the year in Gregorian calendar.
  4. Return Value: The function returns the Gregorian date converted to a Julian Day count. Examples:
    Input : $month=3, $day=31, $year=2018 
    Output : 2458209
    
    Input : $month=4, $day=27, $year=2018
    Output : 2458236
    
    Below program illustrate the gregoriantojd() function. Program 1: The program below demonstrates the use of gregoriantojd() function.
    <?php
    // PHP program to demonstrate the
    // use of gregoriantojd() function 
      
    // converts date to julian integer 
    $jd=gregoriantojd(4, 27, 2018);
      
    // prints the julian day integer
    echo ($jd);
    ?>
    
                        
    Output:
     2458236
    Program 2: The program below demonstrates when day and month out of range.
    <?php
    // PHP program to demonstrate the
    // use of gregoriantojd() function 
      
    // converts date to julian integer 
    // month is out of range
    $jd=gregoriantojd(4, 32, 2018);
      
    // prints the julian day integer
    echo ($jd), "\n"
      
      
    // day is out of range
    $jd=gregoriantojd(13, 29, 2018);
    echo ($jd); 
    ?>
    
                        
    Output:
    0
    0
    Reference: http://php.net/manual/en/function.gregoriantojd.php

    Last Updated : 27 Apr, 2018
    Like Article
    Save Article
    Previous
    Next
    Share your thoughts in the comments
Similar Reads