Cron Job in Cpanel - Timezone issue

6/26/2018

I have a php file which works fine in browser as well as in cron job section. The only thing i am facing is the timezone which i want to run that cron is not syncing with the server timezone.

I want to run the cron job in indian timezone everyday morning @ 7 am. But cron is not running @ 7 am instead it runs in some other time which am unable to identify since it vary each time it runs.I am using Godaddy Hosting services. Any help appreciated.

-- Durgaprasad
cron
kubernetes-cronjob
php
timezone

1 Answer

6/26/2018

you can run cronjob every hour, and check if current hour is 7am of Indian time zone :)

<?php
$time = new DateTime();
$time->setTimezone(new DateTimeZone("Asia/Calcutta"));

if( $time->format("H") == 7 ) {

    // RUN

}
-- MrSmile
Source: StackOverflow