Get the day of the week from a date in PHP

Josh Sherman
1 min read
Software Development 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.

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.

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.

echo date('N' strtotime('2015-07-20')); // 1-7
Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

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.

Currently Reading

Parasie Eve

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles