Home php Day of week by date

Day of week by date




There is an array with dates of this type 2016-12-15,2016-12-12 …
How to determine the day of the week by date

$ days = array (
  'Sunday', 'Monday', 'Tuesday', 'Wednesday',
  'Thursday Friday Saturday'
foreach ($ date_time as $ key = & gt; $ val) {
  echo ($ days [(date ('w'))]. $ val);

Answer 1, authority 100%


date () function you are using has two parameters. The first is the format string, and here you are using the correct w format, which returns the number of the day of the week, where 0 is Sunday.

The second parameter is the timestamp, by default this parameter is equal to the current date and time. Therefore, you should translate your date strings to UNIX TIMESTAMP using the appropriate function strtodate () . Well, that’s all.

$ dates = ['2016-12-15', '2016-12-25', '2017-01 -26 '];
$ days = [
  'Sunday', 'Monday', 'Tuesday', 'Wednesday',
  'Thursday Friday Saturday'
foreach ($ dates as $ d) {
  print_r ([
    'date' = & gt; $ d,
    'dayOfWeek' = & gt; $ days [date ("w", strtotime ($ d))]

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions