Skip to content

Instantly share code, notes, and snippets.

@wesamly
Last active August 29, 2015 14:21
Show Gist options
  • Save wesamly/622d481b05f0586c54e4 to your computer and use it in GitHub Desktop.
Save wesamly/622d481b05f0586c54e4 to your computer and use it in GitHub Desktop.
Execute code within given time range
<?php
$y = date('Y');
$m = date('m');
$d = date('d');
$restrictStart = mktime(0, 30, 0, $m, $d, $y);
$restrictEnd = mktime(1, 30, 0, $m, $d, $y);
$time = time();
if ($time < $restrictStart || $time > $restrictEnd) {
die('not yet!');
}
//Code to execute here
@wesamly
Copy link
Author

wesamly commented May 18, 2015

You can set up a cron job that runs every minute, for example, and code will make sure to execute only when time between 00:30 and 01:30.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment