Posted By

vagrantradio on 07/13/10


Tagged

wordpress


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

jackkeller
manavecplan
clintonhalpin
yanseo


Display based on time of day


 / Published in: PHP
 

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

Display anything based on the time of day

  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

Report this snippet  

You need to login to post a comment.