Return to Snippet

Revision: 50348
at August 18, 2011 09:07 by claudiowebdesign


Initial Code
function giorni_ita( $short=false, $offset=0 ){
	$week = ( 1 => 'Lunedì', 2 => 'Martedì', 3 => 'Mercoledì', 
			4 => 'Giovedì', 5 => 'Venerdì', 6 => 'Sabato', 7 => 'Domenica' );
	$weekshort = ( 1 => 'Lun', 2 => 'Mar', 3 => 'Mer', 4 => 'Gio', 5 => 'Ven', 6 => 'Sab', 7 => 'Dom' );
	$day = (date('N')+$offset < 1) ? 7+date('N')+$offset : ((date('N')+$offset>7) ? date('N')+$offset-7 : date('N')+$offset);

	return $short ? $weekshort[$day] : $week[$day];
}

Initial URL

                                

Initial Description
That snippet return the name of the day (in Italian, but you can easily change that). Giving a value to $offset permits to refer to a day that isn't today, and setting $short to True permits to return a three character shorthand.

Initial Title
Return the name of a day as a string

Initial Tags

                                

Initial Language
PHP