WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I' like to run a cron every 24 hours at midnight PST ( = GMT -8 )

This is what I have

if ( !wp_next_scheduled( 'cron_hook' ) ) {
    //reset on 00:00 PST ( GMT -8 ) == GMT +16
    $timeoffset = strtotime('midnight')+((24-8)*HOUR_IN_SECONDS);
    if($timeoffset < time()) $timeoffset+(24*HOUR_IN_SECONDS);
    wp_schedule_event($timeoffset, 'daily', 'cron_hook');

This sets a daily cron on midnight GMT -8 (24-8) and postpone it 24 hours if it's already in the past so the cron doesn't get triggered at the time of creating.

Am I correct with this approach or do I miss something?

I've already tested it but since my server is running with GMT + 0 I cant verify that for other timezone

share|improve this question
For midnight of current time, based on WordPress' setting for GMT offset I use strtotime( current_time( 'D' ) ) – JPollock Jun 21 '15 at 23:43
up vote 1 down vote accepted


WP Cron jobs do not run at specific times, they are approximate, and all timestamps should be UTC, as WordPress always deals in UTC timestamps. If you want midnight PST, you'll want to specify 8PM UTC.

Also for example, your above code suggests midnight PST, but it may not run at midnight PST. If nobody visits the site at the specified time, and there's 4 hours before someone arrives, then the cron job will occur at 4am.

If you're wanting accurate cron jobs that are not approximate, you will need to setup a server cron job to call the wp cron URL at fixed intervals.

I would also choose a more specific name than 'cron_hook' to prevent clashes and issues in the future

You can test this easily by just figuring out what time midnight PST is in UTC, aka 8AM, does your cornjob fire at 8AM UTC?

share|improve this answer
Yeah a knew that cron doesn't trigger at this time but this doesn't matter in this case cause the plugin were I use it needs to run anyway (which triggers the cron). The plugin should reset a counter at this time and the counter only counts if someone hit the site 'cron_hook' is just a the example. I use a prefixed hook name in my case. Thanks Tom, this answered my question! – revaxarts Jan 25 '13 at 13:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.