Get the day of the week from a date in PHP

Typical of PHP, it’s very easy to get the day of the week from a date, but they
also provide the data in multiple format. Three in fact.

The first, and arguably the most straight forward is to get the textual name of
the day of the week.

<?php
echo date('l' strtotime('2015-07-20' // Sunday-Saturday

That’s all well and good, unless you need the day of the week in a language
other than English. In that scenario you could get a numerical value for a date
and conver it yourself.

Of course there are two different numbering schemes. The first and older
numbering schemes is zero-based starting with Sunday.

<?php
echo date('w' strtotime('2015-07-20' // 0-6

The second numbering scheme, added in PHP 5.1 conforms to ISO-8601. It starts
with 1 for Monday and moves Sunday to the end at 7.

<?php
echo date('N' strtotime('2015-07-20' // 1-7
Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.


If you found this article helpful, please consider buying me a coffee.