Orionsbelter Posted July 18, 2008 Share Posted July 18, 2008 ok i do not know how to do this but really need to know, for example i need it to be like this if(time(); == 12:00pm){ echo"Its midnight";} that is not real code but if it was simple it would be like that. does anyone knwo how to do it? Quote Link to comment https://forums.phpfreaks.com/topic/115396-time-function-do-some-time-at-a-certian-time/ Share on other sites More sharing options...
matthewhaworth Posted July 18, 2008 Share Posted July 18, 2008 You'd have more luck with the date() function because there are an infinite amount of times in which it is midnight. <?php if(date("G") == "0") { echo "it's midnight"; } ?> and so on.. P.s. not that it matters, but strictly speaking 12.00pm is midday lol. 12.00am is midnight. Quote Link to comment https://forums.phpfreaks.com/topic/115396-time-function-do-some-time-at-a-certian-time/#findComment-593245 Share on other sites More sharing options...
Orionsbelter Posted July 18, 2008 Author Share Posted July 18, 2008 hmmm that is hard to work out how to use can you show me what it would look like if i wanted it to be 7:00pm instead of 12:00 pm thank you, owell i thought it was thanks for tell me though Quote Link to comment https://forums.phpfreaks.com/topic/115396-time-function-do-some-time-at-a-certian-time/#findComment-593246 Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 If your planning on running a certain code at certain times of the day, your expecting people to activate that script at that time. Have a look into Cron Jobs. EDIT: Check the date() function. G returns 24 hour time without leading zero's... 0 = midnight. 19 = 7pm Quote Link to comment https://forums.phpfreaks.com/topic/115396-time-function-do-some-time-at-a-certian-time/#findComment-593249 Share on other sites More sharing options...
Schlo_50 Posted July 18, 2008 Share Posted July 18, 2008 Would this not do? <?php $current_time = date('G'); if($current_time == "19") { print "It's 7:00pm."; } ?> As ProjectFear says though, making a script work without someone accessing it would be trickier.. Quote Link to comment https://forums.phpfreaks.com/topic/115396-time-function-do-some-time-at-a-certian-time/#findComment-593251 Share on other sites More sharing options...
matthewhaworth Posted July 18, 2008 Share Posted July 18, 2008 You're better off using a switch/case if you want to have lots of different messages. <?php switch(date("G")) { case "7": echo "It is 7.00am"; break; case "12": echo "It is 12.00pm - Midday : ]"; break; case "0": echo "It is midnight!"; break; default: echo "This will display if the date function returns a value that hasn't been dealt with previously"; break; } ?> Orr... if you really want to stick to the if .. else.. method.. <?php if(date("G") == "0") { echo "it is midnight"; } elseif(date("G") == "7") { echo "it is 7.00am"; } elseif(date("G") == "[YOUR TIME HERE]") { echo "..."; } else { echo "This will display if the date function returns a value that hasn't been dealt with previously"; } ?> It works on a twenty four hour clock, you just simply change the numbers "0" or "7" to whatever time you want on a twenty four hour clock To schlo_50: No, because the date output is not in the format HH:MM. It simply returns H in 24 hour clock format.. you can however change the date function's parameters to produce such an output if you wished and then do it like that though. Quote Link to comment https://forums.phpfreaks.com/topic/115396-time-function-do-some-time-at-a-certian-time/#findComment-593253 Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 Would this not do? <?php $current_time = date('G'); if($current_time == "19:00") { print "It's 7:00pm."; } ?> It doesn't return it as 19:00, it just returns it as 19. As ProjectFear says though, making a script work without someone accessing it would be trickier.. Not necessarily, read up on it. It can be quite handy. Quote Link to comment https://forums.phpfreaks.com/topic/115396-time-function-do-some-time-at-a-certian-time/#findComment-593255 Share on other sites More sharing options...
Schlo_50 Posted July 18, 2008 Share Posted July 18, 2008 lol - Just editted. Quote Link to comment https://forums.phpfreaks.com/topic/115396-time-function-do-some-time-at-a-certian-time/#findComment-593257 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.