Forum Moderators: coopster

Message Too Old, No Replies

More efficient way to write this?

execute script only during certain times of the day

         

jake66

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

10+ Year Member



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.

TheMadScientist

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

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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';
}

andrewsmd

5:02 pm on Nov 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The madscientist is correct.