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.
- $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).
- $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 Sunday, Monday, Tuesday 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.
php
<?php
$jd =gregoriantojd(4, 27, 2018);
echo jddayofweek( $jd );
?>
|
Output:
5
Program 2: The program below demonstrates the output when mode is 1.
php
<?php
$jd =gregoriantojd(4, 27, 2018);
echo jddayofweek( $jd , 1);
?>
|
Output:
Friday
Program 3: The program below demonstrates the output when mode is 2.
php
<?php
$jd =gregoriantojd(4, 27, 2018);
echo jddayofweek( $jd , 2);
?>
|
Output:
Fri
Program 4: The program below demonstrates the output when mode is out of range.
php
<?php
$jd =gregoriantojd(4, 27, 2018);
echo jddayofweek( $jd , 4);
?>
|
Output:
5
Reference:
http://php.net/manual/en/function.jddayofweek.php
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
05 Oct, 2021
Like Article
Save Article