harryuk Posted May 30, 2011 Share Posted May 30, 2011 Hello fellow php friends, Im having abit of trouble trying to echo out a statement at certain times of the day. for example how would you echo out 'Good Morning' between the times of 01am to 11.59am then echo out 'Good afternoon' between times of 12pm and 6pm and so on. Please help!!!!! :D Quote Link to comment https://forums.phpfreaks.com/topic/237851-how-do-you-echo-date-functions-on-certain-times-of-the-day/ Share on other sites More sharing options...
silkfire Posted May 30, 2011 Share Posted May 30, 2011 Use mktime and then compare with mktimes of your intervals. Quote Link to comment https://forums.phpfreaks.com/topic/237851-how-do-you-echo-date-functions-on-certain-times-of-the-day/#findComment-1222255 Share on other sites More sharing options...
harryuk Posted May 30, 2011 Author Share Posted May 30, 2011 hey thanks for your reply. I am having a little play and still no good. Would you mind posting me an example to see what i am missing??? many thanks Quote Link to comment https://forums.phpfreaks.com/topic/237851-how-do-you-echo-date-functions-on-certain-times-of-the-day/#findComment-1222288 Share on other sites More sharing options...
jcbones Posted May 30, 2011 Share Posted May 30, 2011 $time = date('G'); if(($time == '1') || ($time > '1' && $time < '12')) { echo 'Good morning!'; } elseif(($time == '12') || ($time > '12' && $time < '18') { echo 'Good afternoon!'; } else { echo 'Good night!'; } Quote Link to comment https://forums.phpfreaks.com/topic/237851-how-do-you-echo-date-functions-on-certain-times-of-the-day/#findComment-1222294 Share on other sites More sharing options...
harryuk Posted May 30, 2011 Author Share Posted May 30, 2011 Thanks!!! Thats Great Quote Link to comment https://forums.phpfreaks.com/topic/237851-how-do-you-echo-date-functions-on-certain-times-of-the-day/#findComment-1222305 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.