PHP day of week numeric to day of week text
Create an array to map numeric DOWs to text DOWs.
$dowMap = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
If you need locale support, load the dow of some random date (epoch (0) would be a good date for example) and then for the next 6 days and build the dow map dynamically.
day of the week to day number (Monday = 1, Tuesday = 2)
$day_of_week = date('N', strtotime('Monday'));
PHP day of week numeric to day of week text not English
nl_NL
is a typical Unix style locale name. On Windows, locales follow a different format. You want "nld", "holland", or "netherlands".
Additionally, date()
is not locale-aware. You probably want strftime()
.
Convert Number to Day of Week
Just put the days in an array using the day of the week as the key. Then use date('N')
to get the day of the week and use that as they key to access that array value.
$days = [
1 => 'Sunday',
2 => 'Monday',
3 => 'Tuesday',
4 => 'Wednesday',
5 => 'Thursday',
6 => 'Friday',
7 => 'Saturday'
];
echo $days[date('N')];
Getting Day name from day of week
You could use the date function, with the format l
:
l (lowercase 'L')
A full textual representation of the day of the week
http://php.net/manual/en/function.date.php
and use the fact that Sunday is 0:
echo date('l', strtotime("Sunday +{$day_number} days"));
Or as a function:
function getDayNameFromDayNumber($day_number) {
return date('l', strtotime("Sunday +{$day_number} days"));
}
How to find the date of a day of the week from a date using PHP?
I think this is what you want.
$dayofweek = date('w', strtotime($date));
$result = date('Y-m-d', strtotime(($day - $dayofweek).' day', strtotime($date)));
Related Topics
PHP How to Get the Base Domain/Url
How to Use Two Submit Buttons, and Differentiate Between Which One Was Used to Submit the Form
Get Date for Monday and Friday for the Current Week (Php)
Simple Comet Example Using PHP and Jquery
How to Use PHP in a JavaScript Function
Using Laravel Socialite to Login to Facebook
Select Within 20 Kilometers Based on Latitude/Longitude
Inserting Now() into Database with Codeigniter's Active Record
PHP Datetime Microseconds Always Returns 0
How to Install an Older Version of PHPunit Through Pear
How to Access a Different Controller from Inside a Controller Symfony2
PHP Dom Get Nodevalue HTML? (Without Stripping Tags)
How to Send Notification to Android from PHP
Adding Multiple Items to Woocommerce Cart at Once
How to Wrap Long Lines Without Spaces in HTML