Wednesday, November 20, 2024
Google search engine
HomeLanguagesPHP | jddayofweek() Function

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 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
// 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);
?>


Output: 

5

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

php




<?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);
?>


Output: 

Friday

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

php




<?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);
?>


Output: 

Fri

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

php




<?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);
?>


Output: 

5

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

RELATED ARTICLES

Most Popular

Recent Comments