Log in

View Full Version : PHP Time Thingy..



LMS16
13-01-2011, 08:22 AM
Hey,

A little tricky question (or simple :P)
Ive got a script that I am running on a 5 minute cron & want it only to run after 07:30 and to stop running after 20:00.

How would I make PHP do this?

I thought of something like..


if(date("H:i") >= date("H:i", "07:30") && date("H:i") <= date("H:i", "20:00")){
echo "The time is after 07:30 and before 20:00";
exit();
}else{
echo "The time is before 07:30 or after 20:00";
exit();
}


Doesnt work though :S someone help? +REP :)!

Lew.

Johno
13-01-2011, 02:22 PM
This should hopefully work :)


<?php

date_default_timezone_set("Europe/London");

if ((int)date("Hi") >= 0730 && (int)date("Hi") <= 2000){
echo "The time is after 07:30 and before 20:00";
exit();
}else{
echo "The time is before 07:30 or after 20:00";
exit();
}

?>

Want to hide these adverts? Register an account for free!