On Tue, 2007-05-22 at 12:46 -0400, Bosky, Dave wrote:
> How can I convert the numerical day of week to the string version?
> 
> Example, if the day of the week is 1 I would like to print out 'Sunday'.

I saw a bunch of bad examples given to you that completely ignore any
available locale information... so here's a better version:

<?php

function dayIdToName( $id )
{
    static $days = null;
    if( $days === null )
    {
        $control = gmmktime( 12, 1, 1, 5, 20, 2007 );
        for( $i = 0; $i < 7; $i++ )
        {
            $days[$i] = gmdate( 'l', $control + ($i * 24 * 60 * 60) );
        }
    }

    return isset( $days[$id] ) ? $days[$id] : null;
}

?>

If you want Monday to be the first day of the week, just use a date for
gmmktime() that falls on a Monday.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to