Welcome to WebmasterWorld Guest from 18.206.168.65

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

More efficient way to write this?

execute script only during certain times of the day

     
4:00 am on Nov 13, 2009 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 2, 2005
posts:505
votes: 0


if (date("H") < '11' ¦¦ date("H") >'19'){
//do nothing. no code here.
}else{
if (tep_not_null(GLOBAL_ADMIN_NOTE)){
//echo 'stuff here';
}
}

I can't figure out how to set the times properly. Right now, it works as-is, but I'd like to be able to join both if statements.

4:07 am on Nov 13, 2009 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member themadscientist is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 14, 2008
posts:2910
votes: 62


Why not reverse the first if and include the file with the else if you need it?

(You could also only check the date once... It might not be a 'gain' unless you use the hour again, but a thought you might use later, say with a 'for' or something...)


$hour=date("H");
if ($hour > '11' && $hour < '19') {
include_once 'file_with_else.php';
}

Then to put them together you could:
(It looks like anyway.)


$hour=date("H");
if ($hour > '11' && $hour < '19' && tep_not_null(GLOBAL_ADMIN_NOTE)) {
include_once 'file_with_else.php';
}
5:02 pm on Nov 13, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


The madscientist is correct.