Before asking for help I would like to clarify that I don’t have advanced skills on PHP. What I want to achieve is to display different messages for every period of time that I set (I need this to LOOP every day). After reading this -> http://codex.wordpress.org/Function_Reference/current_time I tried to check:

$my_time = current_time('mysql');
if ($my_time >= 14 && $my_time <= 16) {
    echo 'Do your homework';
} else if ($my_time > 14 && $my_time <= 18) {
    echo 'Clean up the house';
} else if ($my_time > 18 && $my_time <= 20) {
    echo 'Go Shopping';
  .
  .
  .
  .
  .
} else {
    echo 'Lets start over!'
}

Where 14, 16, 18, 20 is the time (24hour format). However this did not work. When I echo current_time(‘mysql’), it returns the date and the time so even if it could work, it wouldn’t loop because of the date, right? Thanks in advance.

2 Answers
2

You would just need to format the time that is returned by current_time() with the php date() function like this:

$my_time = date('G', current_time('timestamp'));

The param ‘G’ tells the function you just want to have the hour part (0 to 23) of the date. Have a look here: http://www.php.net/manual/en/function.date.php

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *