csi csi -4 years ago 144
PHP Question

PHP day of week numeric to day of week text

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
to get
? If I have '0' as
, how can I make
$dow_text = 'Sun'
? Yes a
statement could do the job, but I’m looking for a more elegant solution.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download