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.
You would just need to format the time that is returned by current_time() with the php date() function like this:
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
You’re right in that it is a WordPress function, and thus I removed my comment. However, this is still only related to WordPress, because of this being a WordPress function.
This has more to do with what a timestamp is and how you can work with it.
References:
date
function