8

How do I set the Laravel scheduler to run a task at a specific time in a certain timezone? The server is set to UTC, but I want to run the task at 12 noon every Monday in the Pacific/Auckland timezone.

E.g. this will work, but the timezone is UTC:

protected function schedule(Schedule $schedule) {
    $schedule->command('run-report')->weekly()->mondays()->at('12:00'));
}
Petah
  • 45,477
  • 28
  • 157
  • 213

2 Answers2

19

You can do it using timezone() method:

$schedule->command('run-report')->weekly()->mondays()->at('12:00')->timezone('Pacific/Auckland');
jedrzej.kurylo
  • 39,591
  • 9
  • 98
  • 107
  • 2
    It would be hard to put all methods in the Laravel guide, but you can always check the API docs (e.g. https://laravel.com/api/5.1/Illuminate/Console/Scheduling/Event.html) or just browse the code – jedrzej.kurylo Jan 15 '16 at 06:34
  • Hmm, so I tried this, left it for 2 weeks, but it never got triggered. – Petah Feb 01 '16 at 21:07
  • 1
    when you call timezone() it just sets the timezone that is later applied to a DateTime object being used to compare current time with what you set in the scheduler - it can only impact the time, but won't prevent the command from running. I can't really tell why your task was not executed - you need to do some debugging on your own. Make sure that schedule:run command was run, check if there are no errors in the log files, maybe add some logging on your own – jedrzej.kurylo Feb 02 '16 at 22:56
0

The scheduler time zone is not working in laravel 8.x.

  • While this may be true, your answer could be improved by adding a link to supporting documentation and including a workaround if one exists. – Besworks Apr 05 '22 at 14:41
  • Sorry, the time zone is working fine in laravel 8.x. I agree with [jedrzej.kurylo](https://stackoverflow.com/a/34801511/2979237) post. – Peer Mohaideen Apr 08 '22 at 05:16