/** * Returns day of week for a given date (0 = Sunday). * * @param mixed $date * (optional) A date object, timestamp, or a date string. * Defaults to NULL, which means use the current date. * * @return int * The number of the day in the week. */ public static function dayOfWeek($date = NULL) { if (!$date instanceof DrupalDateTime) { $date = new DrupalDateTime($date); } if (!$date->hasErrors()) { return $date->format('w'); } return NULL; }