Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DateHelper.php

function 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()
DateHelper::dayOfWeekName in core/lib/Drupal/Core/Datetime/DateHelper.php
Returns translated name of the day of week for a given date.

File

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

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal