3

I need to get day of week by given date, but don't know how.

It's my homework(actually question wizard testing) and I don't know where should I start

function weekDay($date) {
  return 'Friday'; 
}

I expect to get actual weekday, but always receive Friday.

vp_arth
  • 14,461
  • 4
  • 37
  • 66
  • 2
    Did you try to put your question on Google / StackOverflow search engine ? You will find a lot of solutions : https://stackoverflow.com/questions/12835133/how-to-find-the-date-of-a-day-of-the-week-from-a-date-using-php – Vincent Decaux Jun 21 '18 at 17:32
  • You have this solution at: https://stackoverflow.com/questions/12835133/how-to-find-the-date-of-a-day-of-the-week-from-a-date-using-php?noredirect=1&lq=1 – Luma Macagnan Jun 21 '18 at 17:45
  • 1
    It's interesting but no answers in that question use createFromFormat – vp_arth Jun 21 '18 at 17:47

1 Answers1

6

Try like this way,

<?php
$date = DateTime::createFromFormat('Y-m-d', '2018-06-21');
echo $date->format('l'); # l for full week day name
?>

Ref.: http://php.net/manual/en/datetime.createfromformat.php

Demo: https://eval.in/1025956

A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103