Convert date to day name e.g. Mon, Tue, Wed
This is what happens when you store your dates and times in a non-standard format. Working with them become problematic.
$datetime = DateTime::createFromFormat('YmdHi', '201308131830');
echo $datetime->format('D');
See it in action
echo date('D', strtotime($date));
echo date('l', strtotime($date));
Result
Tue
Tuesday
For other language use day of week to recognize day name
For example for Persian use below code
$dayName = getDayName(date('w', strtotime('2019-11-14')));
function getDayName($dayOfWeek) {
switch ($dayOfWeek){
case 6:
return 'شنبه';
case 0:
return 'یک شنبه';
case 1:
return 'دو شنبه';
case 2:
return 'سه شنبه';
case 3:
return 'چهار شنبه';
case 4:
return 'پنج شنبه';
case 5:
return 'جمعه';
default:
return '';
}
}
More info : https://www.php.net/manual/en/function.date.php
Your code works for me
$date = '15-12-2016';
$nameOfDay = date('D', strtotime($date));
echo $nameOfDay;
Use l
(lowercase L) instead of D
, if you prefer the full textual representation of the name.