Display based on time of day


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

Display anything based on the time of day


Copy this code and paste it in your HTML
  1. $thehour = date('G');
  2.  
  3. foreach (range(0, 7) as $number) {
  4. $morning[$number] = $number;
  5. }
  6. foreach (range(8, 15) as $number) {
  7. $day[$number] = $number;
  8. }
  9. foreach (range(16, 23) as $number) {
  10. $evening[$number] = $number;
  11. }
  12.  
  13. if(in_array($thehour,$morning)) { echo 'it\'s morning'; } // 00:00 - 07:59am
  14. elseif(in_array($thehour,$day)) { echo 'it\'s day'; } // 08:00 - 15:59pm
  15. elseif(in_array($thehour,$evening)) { echo 'it\'s evening'; } // 16:00pm - 23:59pm

URL: http://wordpress.org/support/topic/249486

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.