PHP day of week numeric to day of week text

Related searches

This may be really easy but I can't find a PHP function to do this...

OK so

$dow_numeric = date('w');

gives the numeric day of the week 0-6 for Sunday to Saturday.


$dow_text = date('D');

gives the 3 letter abbreviation for the text day of the week (Sun, Mon, etc.)

Is there a function or easy way to use $dow_numeric to get $dow_text? If I have '0' as $dow_numeric, how can I make $dow_text = 'Sun'? Yes a switch statement could do the job, but I’m looking for a more elegant solution.

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.

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,� w - A numeric representation of the day (0 for Sunday, 6 for Saturday) z - The day of the year (from 0 through 365) W - The ISO-8601 week number of year (weeks starting on Monday) F - A full textual representation of a month (January through December) m - A numeric representation of a month (from 01 to 12)

Bit of a hack, but:

$dow_text = date('D', strtotime("Sunday +{$dow_numeric} days"));

jddayofweek - Manual, Returns the day of the week. Can return a string or an integer depending on the mode. Parameters �. julianday. A julian day number as� ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0) 1 (for Monday) through 7 (for Sunday) The much more convenient way is to identify

It's not popular, but there's actually a function jddayofweek for this in PHP. You can call it with the second parameter as 1 to get full gregorian week day name or 2 for the abbreviated name.

e.g. jddayofweek(2, 2); #returns Wed

Note that for this function, numbers start at Monday. So Monday=0, Tuesday=1, ...

date - Manual, If a non-numeric value is used for timestamp , FALSE is returned and an version and your choice of 'w' or 'N' for the Numeric representation of the day of the week: echo "Day ",date('w',strtotime('2016-10-02 Monday next week'))," of next� This can produce different, and seemingly incorrect, results depending on your PHP version and your choice of 'w' or 'N' for the Numeric representation of the day of the week: <?php echo "Today is Sun 2 Oct 2016, day " , date ( 'w' , strtotime ( '2016-10-02' )), " of this week.

To get Sunday to Saturday from numeric day of the week 0 to 6:

//For example, our target numeric day is 0 (Sunday):
$numericDay = 0; //assuming current date('w')==0 and date('D')=='Sun';

Solution-1: Using PHP's built-in function jddayofweek() which starts from Monday whereas date('w') starts from Sunday:

jddayofweek($numericDay-1, 1); //returns 'Sun', here decreasing by '-1' is important(!)

//jddayofweek(0, 1); //returns 'Mon';
//jddayofweek(0, 2); //returns 'Monday';

Solution-2: Using a trick(!):

date('D', strtotime("Sunday +{$numericDay} days")); //returns 'Sun';

//date('l', strtotime("Sunday +{$numericDay} days")); //returns 'Sunday';

Relative Formats - Manual, ordinal space dayname space 'of', Calculates the x-th week day of the current month. day-of-week is the same as the day-of-week used in the date/time string . "number week dayname" will first add the number of weeks, but does not� Possible Duplicate: How to find day of week in php. I want to get the day of the week of the selected date. For example 05/19/2011 = Thursday

function getDay(){
    $dowMap = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
    $dow_numeric = date('w');
    return $dowMap[$dow_numeric];

PHP: Get the day of the week from a date string., good article! but how to find number of week, 1,2,3,4,5,6,7? Like � Reply � Mark as spam � 11w. (By default Sunday is considered the first day of the week; 1). SELECT DateofSale, Weekday([DateofSale],2) AS NewWeekDay FROM ProductSales; Returns the values from the field "DateofSale" and number representing the 'Weekday' of these date values. (considering Monday as first day of the week).

If you want to get the full day name of the week, such as: Monday, Tuesday, etc. Enter the following TEXT formula in the Cell C1 that you want to get the day name of the week, then press ENTER: =TEXT(B1,"dddd") Get a Day Name of the Week Using WEEKDAY and CHOOSE function. The WEEKDAY function will get a day number of the week form a date. We

To get the number of the day of week. Using DATEPART function: SELECT DATEPART(WEEKDAY, GETDATE()) /* Result */ 4

home Front End HTML CSS JavaScript HTML5 php.js Twitter Bootstrap Responsive Web Design tutorial Zurb Foundation 3 tutorials Pure CSS HTML5 Canvas JavaScript Course Icon Angular React Vue Jest Mocha NPM Yarn Back End PHP Python Java Node.js Ruby C programming PHP Composer Laravel PHPUnit ASP.NET Database SQL(2003 standard of ANSI

  • Super easy and agree... so I take it there isn't a function already though.
  • Clever hack that reinvents the wheel :)
  • It's not hacky, it's slick! ;-)
  • Alternatively, use date('l') (lowercase L) for a full day name. more info
  • Great! But what are the {} for?
  • The default start of the week is Monday. So if your Sunday == 0, everything is off by a day. Keep that in mind.
  • This should be the best answer.
  • Julian day 0 = January 1, 4713BC (a Monday). That's why 0 = Monday; 1 = Tuesday etc. If you want to have 0 -> Sunday (etc) then you should use jddayofweek($dow_numeric - 1, 2); (or , 1 for long day names)
  • @klawipo, no - (and others, see - I believe "popular' in the answer means "not as well known" - certainly it was a new function for me (and I've been using PHP for 25+ years!)
  • I would recommend using the provided built in constants CAL_DOW_SHORT and CAL_DOW_LONG with jddayofweek. Constants definitions are less likely to change than their values.
  • Great idea with strtotime!