Search code examples
phpdatabasecron

Update DB field at midnight each day according to user timezone


I have a table http://sqlfiddle.com/#!2/c7c85/1 having timezone and timezone_offset field into it,where timezone_offset field is in seconds, i need to update the invite_limit for all the users at midnight(when it strike midnight in user timezone) accordingly of their timezone,I know i can run a cron job scheduled to be run at midnight of each day which will execute a script to update the DB. The problem i have is users are from different timezones i need to update the field at stroke of midnight per user basis.


Solution

  • User's last visit timestamp should do the trick here. If it's older than user's last midnight time then reset invite_limit (and visit time as well if you'll use it for this purpose only).