Returns day of week for a given date (0 = Sunday).
mixed $date: (optional) A date object, timestamp, or a date string. Defaults to NULL, which means use the current date.
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;
}