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

Breadcrumb

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

function DateHelper::daysInMonth

Identifies the number of days in a month for a date.

Parameters

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

Return value

int The number of days in the month, or null if the $date has errors.

File

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

Class

DateHelper
Defines Gregorian Calendar date values.

Namespace

Drupal\Core\Datetime

Code

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

API Navigation

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