Cron expression for every 23 hours

You could do every 24 hours like this, every 23 hours would be a little trickier.

<cron_expr>0 23 * * *</cron_expr>

Technically the syntax for every something somethings would be */something, so */23 in your case.

Ie. If you wanted a cron to run every 6 hours, exactly on the hour, it would be,

<cron_expr>0 */6 * * *</cron_expr>

But this expression is only going to be valid for values under 12, as the cron's interpretation of 'every' resets each day.

So for every 23 hours, on the hour, you would be best executing it every hour like so, and doing a modulus of 23 within your script itself.

<cron_expr>0 * * * *</cron_expr>

Then in the method being executed, place this at the start,

$time = time();
if (((($time - ($time % 3600))/3600) % 23) != 0)
  return;

Tags:

Cron