# How to run a CRON task at midnight of each user's local time

**URL:** <https://www.ruby-forum.com/t/how-to-run-a-cron-task-at-midnight-of-each-users-local-time/195854>\
**Category:** Rails\
**Created:** [October 1, 2010, 10:21am UTC](https://www.ruby-forum.com/t/how-to-run-a-cron-task-at-midnight-of-each-users-local-time/195854 "2010-10-01T10:21:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bertly\_the\_coder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b38774/32.png) [@bertly\_the\_coder](https://www.ruby-forum.com/u/bertly_the_coder)\
**Post date:** [October 1, 2010, 10:21am UTC](https://www.ruby-forum.com/t/how-to-run-a-cron-task-at-midnight-of-each-users-local-time/195854/1 "2010-10-01T10:21:15Z")

</div>

I have a job I want to run at midnight of whatever timezone the user  
is in. Right now it runs at midnight, server time. I want to make it  
run every hour and only affect the user’s whose local time, at time of  
running the task, is midnight.

The user database stores the user’s timezone.

Is there a Ruby or Rails command that can check what timezone is at  
midnight, then only run that job on the user’s whose time is midnight?

Any other suggestions on how to run it…if anyone has done this  
before…or has an idea…

Thanks guys  
Sir Bertly.

---

<div class="post-metadata">

**Author:** ![bertly\_the\_coder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b38774/32.png) [@bertly\_the\_coder](https://www.ruby-forum.com/u/bertly_the_coder)\
**Post date:** [October 1, 2010, 10:37am UTC](https://www.ruby-forum.com/t/how-to-run-a-cron-task-at-midnight-of-each-users-local-time/195854/2 "2010-10-01T10:37:38Z")

</div>

I answer this as a common question,dont have much experience in ROR.

you have to run one cron each hour and you have to store the GMT  
difference  
along with the user details.Script you execute using the cron should  
have a  
algorithm to find out the midnight of the user according the GMT  
difference  
you stored.

maybe someone has better idea than this…

Regards  
Cherankrish

On Fri, Oct 1, 2010 at 9:55 AM, bertly\_the\_coder [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Any other suggestions on how to run it…if anyone has done this  
> removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> .  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–  
_Cherankrish_  
removed\_email\_address@domain.invalid  
Skype: cherankrish

QR code :

---

<div class="post-metadata">

**Author:** ![bertly\_the\_coder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b38774/32.png) [@bertly\_the\_coder](https://www.ruby-forum.com/u/bertly_the_coder)\
**Post date:** [October 1, 2010, 11:09pm UTC](https://www.ruby-forum.com/t/how-to-run-a-cron-task-at-midnight-of-each-users-local-time/195854/3 "2010-10-01T23:09:15Z")

</div>

Aah, sounds about right, but, that brings up another issue…Daylight  
savings…  
So here is what I did. I set the rails timezone to the user time zone,  
then  
got the current time according to rails, if within the hour of midnight  
(00h), run the task. This works for now, but may be a bummer if I have a  
large number of users…hopefully I’ll know more then…

Thanks for your response. Helped me jog my thoughts.
