You need to take into account the time zone for sending messages to the crm user right now, just came to the conclusion that you need to do this. Suppose the user has the opportunity to set the time zone field "timezone".

right now a script like this:

// Варианты напоминания $timeto = array( array("timeto" => "day_1","sec" => "86400",), array("timeto" => "houre_1","sec" => "3600"), array("timeto" => "min_30","sec" => "1800"), array("timeto" => "min_15","sec" => "900"), array("timeto" => "min_10","sec" => "600"), ); for ($i = 0; $i < count($timeto); $i++) { $time_to = $timeto[$i]['timeto']; $time_to_sec = $timeto[$i]['sec']; $rem_remember = mysql_query("SELECT * FROM `tasks` WHERE $time_to = '1' and status = '0'"); while($row_remember = mysql_fetch_array($rem_remember)){ $now_date = mktime(); $start_datetime = strtotime("$row_remember[start_date] $row_remember[start_time]"); $end_datetime = strtotime("$row_remember[end_date] $row_remember[end_time]"); $date_rememder = $start_datetime-$time_to_sec; $limit_date_rememder = 60+$date_rememder; // расчет времени вс секундах + 1 минута if ($now_date >= $date_rememder and $now_date <= $limit_date_rememder) { // отправляем письмо } } 

    1 answer 1

    You can store the date and time in a database in UTC format and simply add or subtract the number of hours corresponding to the user's time zone.

     SELECT id, timeto - INTERVAL timezone HOUR, start_date - INTERVAL timezone HOUR, end_date - INTERVAL timezone HOUR FROM tasks WHERE $time_to = '1' and status = '0'" 
    • Well, right now, I can’t redo a huge database and the date is stored there in the form of CILL 00:00:00 - Alexander Sizintsev
    • What time zone is the date and time stored in? You can make an amendment to account for this time zone. - cheops
    • Moscow time in general - Alexander Sizintsev
    • Shift the timezone value by 3 hours so that it takes into account that the countdown does not come from the UTC time zone of 0, but from Moscow -3, i.e. if your user chooses Moscow time, he has timezone = 0, and if UTC: +3 - cheops
    • Plus, one timezone field may not be enough for you, since in some countries winter / summer time is supported. Stackoverflow.com/questions/503294 - cheops