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%
The
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))]
]);
}