PHP jddayofweek() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Calendar

Definition

In PHP, jddayofweek() returns the day of the week for a Julian Day number, either as a number or as a name like Saturday.

Pass a Julian Day (you can get one from gregoriantojd()) and choose the mode. Mode 0 returns a number where 0 is Sunday, mode 1 returns the full day name, and mode 2 returns a three letter short name.

Syntax

Call jddayofweek() with the values you need. Start with this line.

PHP
$day = jddayofweek($jd, CAL_DOW_LONG);
CallWhat it does
jddayofweek($jd, CAL_DOW_DAYNO)Returns an integer from 0 (Sunday) to 6 (Saturday).
jddayofweek($jd, CAL_DOW_LONG)Returns the full day name, such as Saturday.
jddayofweek($jd, CAL_DOW_SHORT)Returns the short day name, such as Sat.

The mode constants are CAL_DOW_DAYNO (0), CAL_DOW_LONG (1) and CAL_DOW_SHORT (2). Any other mode behaves like 0 and returns the number. In the numeric result, Sunday is 0, not Monday.

Library declarations
PHP
jddayofweek(int $julian_day, int $mode = CAL_DOW_DAYNO): int|string

Parameters

ParameterDescription
julian_dayRequired. The Julian Day number, for example from gregoriantojd(1, 1, 2000).
modeOptional. CAL_DOW_DAYNO (0, the default) returns a number, CAL_DOW_LONG (1) returns the full name and CAL_DOW_SHORT (2) returns the three letter name.

Return Value

Return ValueDescription
intWith mode 0 (or an unknown mode), a number from 0 (Sunday) to 6 (Saturday).
stringWith mode 1 or 2, the full or abbreviated English day name.

PHP Examples

Example 1 — Three Modes

Find the weekday for January 1, 2000 using each of the modes.

PHP
<?php
$jd = gregoriantojd(1, 1, 2000);

echo jddayofweek($jd), PHP_EOL;
echo jddayofweek($jd, CAL_DOW_DAYNO), PHP_EOL;
echo jddayofweek($jd, CAL_DOW_LONG), PHP_EOL;
echo jddayofweek($jd, CAL_DOW_SHORT), PHP_EOL;

How It Works

  1. gregoriantojd() converts January 1, 2000 into a Julian Day number.
  2. Without a mode, jddayofweek() uses CAL_DOW_DAYNO and returns the number 6.
  3. In the numbers, 0 is Sunday, so 6 means Saturday.
  4. CAL_DOW_LONG and CAL_DOW_SHORT return Saturday and Sat.

Example 2 — Return Types by Mode

Use var_dump() to see that the result is an integer for mode 0 and a string for the other modes.

PHP
<?php
$jd = gregoriantojd(12, 25, 2024);

var_dump(jddayofweek($jd, 0));
var_dump(jddayofweek($jd, 1));
var_dump(jddayofweek($jd, 2));
var_dump(jddayofweek($jd, 7));

How It Works

  1. December 25, 2024 was a Wednesday, which is number 3 when Sunday is 0.
  2. Mode 0 returns the integer 3.
  3. Mode 1 returns the string Wednesday, and mode 2 returns the string Wed.
  4. An unknown mode like 7 acts like mode 0, so it returns int(3) again.

Example 3 — Weekday or Weekend

Loop over seven days starting on January 1, 2024 and label each one as a weekday or weekend.

PHP
<?php
$start = gregoriantojd(1, 1, 2024);

for ($i = 0; $i < 7; $i++) {
    $jd = $start + $i;
    $number = jddayofweek($jd, CAL_DOW_DAYNO);
    $name = jddayofweek($jd, CAL_DOW_SHORT);

    echo $name, ': ', ($number === 0 || $number === 6) ? 'weekend' : 'weekday', PHP_EOL;
}

How It Works

  1. January 1, 2024 was a Monday, so the loop starts on a Monday.
  2. Adding 1 to the Julian Day moves to the next day.
  3. The number 0 (Sunday) and 6 (Saturday) are treated as the weekend.
  4. The short name from mode 2 makes the output easy to read.

Frequently Asked Questions

It returns the weekday of a Julian Day. With mode 0 you get a number (0 is Sunday), and with mode 1 or 2 you get the English day name in full or short form.
Sunday is 0, Monday is 1, and so on up to Saturday, which is 6. This is different from the ISO standard, where Monday is 1 and Sunday is 7.
Use gregoriantojd(month, day, year) for a Gregorian date. You can also use cal_to_jd() or unixtojd() depending on what you start with.
No. The names are always in English. If you need another language, take the number and map it to your own array of names.
Yes. The calendar extension must be enabled. Add extension=calendar to php.ini or install the php-calendar package if the function is undefined.

Next: jdmonthname()

jdmonthname() returns the name of the month for a Julian Day number, in the calendar and s.

jdmonthname() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful