Return the name of a day as a string


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. function giorni_ita( $short=false, $offset=0 ){
  2. $week = ( 1 => 'Lunedì', 2 => 'Martedì', 3 => 'Mercoledì',
  3. 4 => 'Giovedì', 5 => 'Venerdì', 6 => 'Sabato', 7 => 'Domenica' );
  4. $weekshort = ( 1 => 'Lun', 2 => 'Mar', 3 => 'Mer', 4 => 'Gio', 5 => 'Ven', 6 => 'Sab', 7 => 'Dom' );
  5. $day = (date('N')+$offset < 1) ? 7+date('N')+$offset : ((date('N')+$offset>7) ? date('N')+$offset-7 : date('N')+$offset);
  6.  
  7. return $short ? $weekshort[$day] : $week[$day];
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.