PHP | jddayofweek() Function

The jddayofweek() function is a built-in function in PHP which returns the given day of the week of a Julian integer passed in the argument. The return value is of three types depending on the mode passed in the function. It returns three types of values which represents the day of the week. If the mode is passed as 0, it returns 0, 1, 2… which denotes Sunday, Monday, Tuesday… It returns Sunday, Monday, Tuesday… when 1 is passed as the mode. When 2 is passed as the mode, it returns the abbreviation Sun, Mon, Tue… as the day of the week.

Syntax:

jddayofweek($jd, $mode)

Parameters: The function accepts two parameters as shown above and described below.

  1. $jd – This is a mandatory parameter which specifies the julian day number as integer. The Gregorian calendar date is converted to julian day integer using gregoriantojd($month, $day, $year).
  2. $mode – This is an optional parameter which specifies the type of return value. It accepts value in range 0-2 inclusive. The default value is taken as 0. The three types of mode of return are described below:
    • 0 – When mode is passed as 0, it returns 0, 1, 2, 3.. denoting Sunday, Monday, Tuesday… respectively as the day of the week. This is the default value of mode when no mode parameter is missing or any value out of range is passed.
    • 1 – When mode is passed as 1, it returns Sunday, Monday, Tuesday…
    • 2 – When mode is passed as 2, it returns the abbreviation form of MSunday, Monday, Tuesdae as Sun, Mon, Tues..

Return value: The function returns the day of the week depending on the value of the mode passed in the argument as described above.

Examples:



Input : $jd = 4/27/2018 ,  mode=0 
Output : 5

Input : $jd = 4/27/2018 ,  mode=1 
Output : Friday

Below programs illustrate the jddayofweek() function

Program 1: The program below demonstrates the output when mode is not passed and default mode is taken.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to demonstrate the
// use of jddayofweek() function 
// when second parameter is not passed
  
// converts date to julian integer 
$jd=gregoriantojd(4, 27, 2018);
  
// prints the day on the given date
echo jddayofweek($jd);
?>

chevron_right


Output:

5

Program 2: The program below demonstrates the output when mode is 1.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to demonstrate the
// use of jddayofweek() function 
// when mode is 1
  
// converts date to julian integer 
$jd=gregoriantojd(4, 27, 2018);
  
// prints the day on the given date
echo jddayofweek($jd, 1);
?>

chevron_right


Output:

Friday

Program 3: The program below demonstrates the output when mode is 2.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to demonstrate the
// use of jddayofweek() function 
// when mode is 2
  
// converts date to julian integer 
$jd=gregoriantojd(4, 27, 2018);
  
// prints the day on the given date
echo jddayofweek($jd, 2);
?>

chevron_right


Output:

Fri

Program 4: The program below demonstrates the output when mode is out of range.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to demonstrate the
// use of jddayofweek() function 
// when mode is out of range
  
// converts date to julian integer 
$jd=gregoriantojd(4, 27, 2018);
  
// prints the day on the given date
echo jddayofweek($jd, 4);
?>

chevron_right


Output:

5

Reference:
http://php.net/manual/en/function.jddayofweek.php




My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

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.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.