-2

How to get the day of the week in DateTime ?

I can’t find the way to get the day of the week from a DateTime. It’s can be number or string, both are ok.

$today = new DateTime("today");
echo $ today->//whatever to get Friday, Monday or 5, 0

How to get the day of the week in DateTime ?

Edit: I am using DateTime, not date.

Angel
  • 55
  • 1
  • 10

1 Answers1

0

You can use format() function

$today->format('l') //Sunday through Saturday
$today->format('w') //0 (for Sunday) through 6 (for Saturday)
Ryan Nghiem
  • 2,417
  • 2
  • 18
  • 28