How to Schedule Cron Job Based on Time zone in Laravel

Websolutionstuff | Jan-14-2025 | Categories : Laravel

Scheduling tasks using cron jobs in Laravel is a powerful way to automate repetitive processes like sending emails, cleaning up databases, or running reports. However, when working with applications that cater to users across different time zones, it becomes crucial to schedule these tasks based on the correct time zone.

In this guide, I’ll show you how to schedule cron jobs in Laravel based on specific time zones.

Schedule Laravel job based on time zone

schedule laravel job based on time zone

 

Setup Cron Job

In this step, we'll set up a cron job.

Laravel 11 Cron Job Task Scheduling Example

 

Setting Timezone for a single Command

You can set a specific timezone for single commands using the following command:

<?php

use Illuminate\Support\Facades\Schedule;

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

 

Setting Timezone for All Command

You can set a specific timezone for all commands using the following code:

config/app.php

'schedule_timezone' => 'Asia/Kolkata',

 


You might also like:

Recommended Post
Featured Post
Laravel 10 Send Bulk Mail Using Queue
Laravel 10 Send Bulk Mail Usin...

In this article, we will see laravel 10 send bulk mail using a queue. Here, we will learn about how to send bulk ma...

Read More

Mar-13-2023

Laravel 8 Multiple Database Connections
Laravel 8 Multiple Database Co...

Hello Freinds, In this tutorial we will see laravel 8 multiple database connections. Today I will give you step by st...

Read More

Apr-19-2021

Python Read CSV File Without Header
Python Read CSV File Without H...

In this article, I'll show you how to read CSV files without a header in Python. Sometimes, CSV files don't have...

Read More

Sep-20-2024

How To Change Datepicker Start Date In Angular 15
How To Change Datepicker Start...

In this tutorial, I will guide you through the process of changing the start date of a datepicker component in Angular 1...

Read More

Jul-03-2023