how to use TimeZone with Cron tab

I run a job at specific date[Client time not local time] to send email to my clients. I use cpanel cron job i tried to use cron job with time zone

but it still sending in my local time zone

32 16 08 05 *  /usr/bin/curl CRON_TZ=Africa/Algiers https://www.example.com/SendCron.php?CronID=382 #CronID382END # z93v66 

what wrong i did using Cron_TZ ??


Your CRON_TZ= is in a wrong place in your crontab file, as an option attribute for /usr/bin/curl.

You should instead have it as an environment variable set before the cron entries:

CRON_TZ=Africa/Algiers 

32 16 08 05 *  /usr/bin/curl https://www.example.com/SendCron.php?CronID=382

If you need to have time zone set for a single cron entry on the same single line, it is not possible with the CRON_TZ environment variable, but you need to invoke external env (run a program in a modified environment) to change the TZ:

32 16 08 05 * /usr/bin/env TZ=Africa/Algiers /usr/bin/curl https://www.example.com/Send...

Notice that both changes the time zone for the command, not for cron daemon. The cron daemon just checks whether the fields matches current time or not, regardless of the CRON_TZ variable. The manual page for systemd-cron crontab explains this limitation:

The systemd-cron units runs with a defined timezone. It currently does not support per-user timezones. All the tasks: system's and user's will be run based on the configured timezone. Even if a user specifies the TZ environment variable in his crontab this will affect only the commands executed in the crontab, not the execution of the crontab tasks themselves.

If you need to run the schedules based on timezone, you must change the server timezone, e.g.:

ln -sf /usr/share/zoneinfo/Africa/Algiers /etc/localtime