How to Schedule Laravel Cron Job Based on Timezone?

By Hardik Savani December 11, 2024 Category : Laravel

In this post, I will show you how to schedule command based on timezone in laravel application.

By default, Laravel's scheduled commands use the timezone specified in the application configuration file. However, you can also configure cron jobs to run based on a specific timezone. Here are two methods to set up cron jobs with a timezone:

Setup Cron Job:

You can see the following URL to setup cron job in laravel:

Laravel Setup CRON JOB

Setting Timezone for One Command:

You can set specific timezone for one command like the following way:

routes/console.php

<?php

use Illuminate\Support\Facades\Schedule;

Schedule::command('send:user-mail')
         ->timezone('Asia/Kolkata')
         ->at('12:00')

Setting Timezone for All Command:

You can set specific timezone for all commands like the following way:

config/app.php

'schedule_timezone' => 'Asia/Kolkata',

I hope you it can help you.

Thank you

Tags :
Shares