Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get weekday by date [duplicate]

Tags:

date

php

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.

like image 598
vp_arth Avatar asked Sep 15 '25 12:09

vp_arth


1 Answers

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

like image 54
Always Sunny Avatar answered Sep 18 '25 06:09

Always Sunny