Greywacke Posted December 1, 2010 Share Posted December 1, 2010 hi there,the date add function i use, is as follows: function dateadd($interval,$date = "") { if ($date == "") { $now = getdate(strtotime(convert_tz(date("Y-m-d H:i:s", time()),"SAST"))); } else { $now = getdate(strtotime(convert_tz($date,"SAST"))); } return date("Y-m-d H:i:s",mktime(23,59,59,$now["mon"],$now["mday"] + $interval,$now["year"]));} convert_tz converts the US Central timezone (where the site is hosted) to South African standard time (where the site is used) - no problem, using a timezone class i downloaded from phpclasses.org.the function which calculates the values to add to the survey queue, which is processed by a cronjob - is as follows: function createtriggers($leadid) { // loop through survey types and create triggers $sql0 = "SELECT * FROM 20_surveytypes WHERE bigint_ServiceID = ".$GLOBALS["service"]." AND tinyint_OffsetFrom < 2 ORDER BY bigint_SurveyID ASC;"; $result0 = mysql_query_errors($sql0, $conn , __FILE__ , __LINE__ ); $sql1 = "SELECT * FROM 25_serviceleads WHERE bigint_LeadID = ".$leadid.";"; $result1 = mysql_query_errors($sql1, $conn , __FILE__ , __LINE__ ); if ($result0 && $result1) { if ($row1 = mysql_fetch_array($result1)) { while ($row0 = mysql_fetch_array($result0)) { $osf = $row0["tinyint_OffsetFrom"]; switch ($osf) { case 1: $ofs = $row1["timestamp_ExpectedBy"]; break; default: $ofs = $row1["timestamp_LeadCreated"]; } $tss = dateadd($row0["tinyint_SurveyDaysOffset"],$ofs); $sql2 = "INSERT INTO 26_surveyqueue (bigint_SurveyID, bigint_LeadID, timestamp_SurveyTrigger) VALUES (".$row0["bigint_SurveyID"].",".$leadid.",\"".$tss."\");"; $result2 = mysql_query_errors($sql2, $conn , __FILE__ , __LINE__ , true ); } mysql_free_result($result0); } mysql_free_result($result1); }} however, it seems not to be getting $osf (the offset from (time)stamp field)'s value as the digit 1 for the survey type in the table for these - as it's getting the default case for this value. what could be the matter? $ofs is the offset from timestamp. the tinyint_OffsetFrom field has a value for this survey type, 1 - with tinyint_SurveyDaysOffset being -17 for this record. Link to comment Share on other sites More sharing options...
Greywacke Posted December 1, 2010 Author Share Posted December 1, 2010 ahh it seems it got messed up by trying to convert a south african standard time to south african standard time.i modified the createtriggers and dateadd functions to work as follows: function dateadd($interval,$date = "", $ctz = true) { if ($date == "") { if ($ctz) { $now = getdate(strtotime(convert_tz(date("Y-m-d H:i:s", time()),"SAST"))); } else { $now = getdate(strtotime(date("Y-m-d H:i:s", time()))); } } else { if ($ctz) { $now = getdate(strtotime(convert_tz($date,"SAST"))); } else { $now = getdate(strtotime($date)); } } return date("Y-m-d H:i:s",mktime(23,59,59,$now["mon"],$now["mday"] + $interval,$now["year"]));}function createtriggers($leadid) { // loop through survey types and create triggers $sql0 = "SELECT * FROM 20_surveytypes WHERE bigint_ServiceID = ".$GLOBALS["service"]." AND tinyint_OffsetFrom < 2 ORDER BY bigint_SurveyID ASC;"; $result0 = mysql_query_errors($sql0, $conn , __FILE__ , __LINE__ ); $sql1 = "SELECT * FROM 25_serviceleads WHERE bigint_LeadID = ".$leadid.";"; $result1 = mysql_query_errors($sql1, $conn , __FILE__ , __LINE__ ); if ($result0 && $result1) { if ($row1 = mysql_fetch_array($result1)) { while ($row0 = mysql_fetch_array($result0)) { $osf = $row0["tinyint_OffsetFrom"]; switch (intval($osf)) { case 1: $ofs = $row1["timestamp_ExpectedBy"]; break; default: $ofs = $row1["timestamp_LeadCreated"]; } $tss = dateadd($row0["tinyint_SurveyDaysOffset"],$ofs,false); $sql2 = "INSERT INTO 26_surveyqueue (bigint_SurveyID, bigint_LeadID, timestamp_SurveyTrigger) VALUES (".$row0["bigint_SurveyID"].",".$leadid.",\"".$tss."\");"; $result2 = mysql_query_errors($sql2, $conn , __FILE__ , __LINE__ , true ); } mysql_free_result($result0); } mysql_free_result($result1); }} from this code, it is seen that it is not needed to apply the timezone conversion to the dates. this issue has now been resolved! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.