function DateHelper::dayOfWeek

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Datetime/DateHelper.php \Drupal\Core\Datetime\DateHelper::dayOfWeek()

Returns day of week for a given date (0 = Sunday).

Parameters

mixed $date: (optional) A DrupalDateTime object or a date string. Defaults to NULL, which means use the current date.

Return value

int|null The number of the day in the week, or null if the $date has errors.

1 call to DateHelper::dayOfWeek()
DateHelperTest::testDayOfWeek in core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php
@covers ::dayOfWeek[[api-linebreak]]

File

core/lib/Drupal/Core/Datetime/DateHelper.php, line 502

Class

DateHelper
Defines Gregorian Calendar date values.

Namespace

Drupal\Core\Datetime

Code

public static function dayOfWeek($date = NULL) {
  $date = $date ?? 'now';
  if (!$date instanceof DrupalDateTime) {
    $date = new DrupalDateTime($date);
  }
  if (!$date->hasErrors()) {
    return $date->format('w');
  }
  return NULL;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.