Hobbyist_PHPer Posted September 5, 2012 Share Posted September 5, 2012 Hi, I have this application where I am going to store the datetime's in UTC, and then when printed out they will be adjusted by the user's setting's time zone, time difference..., but I'm having an issue... For some reason, this code won't work... <? $timeDiff = $_SESSION['DirectExaminerCompanyTimeZone'] * 3600; echo date('n-d-Y @ g:i a', strtotime($row['OrderTicketStatusDateTime']) $timeDiff); ?> The session variable in this case equals -6 If I code in -6 * 3600 instead of putting in the variable, it works, otherwise it just gives me an error I also tried this, a bit of code I found on Stackoverflow, but no go either... <? echo date('n-d-Y @ g:i a', strtotime($timeDiff, strtotime($row['OrderTicketStatusDateTime']))); ?> Quote Link to comment https://forums.phpfreaks.com/topic/268029-help-with-strtotime/ Share on other sites More sharing options...
requinix Posted September 5, 2012 Share Posted September 5, 2012 What would be even easier is to use date_default_timezone_set. date_default_timezone_set("America/Whatever is for Central"); echo date("n-d-Y @ g:i a', $row['OrderTicketStatusDateTime']); Except you need a timezone string, not a number. Quote Link to comment https://forums.phpfreaks.com/topic/268029-help-with-strtotime/#findComment-1375514 Share on other sites More sharing options...
Hobbyist_PHPer Posted September 5, 2012 Author Share Posted September 5, 2012 What would be even easier is to use date_default_timezone_set. date_default_timezone_set("America/Whatever is for Central"); echo date("n-d-Y @ g:i a', $row['OrderTicketStatusDateTime']); Except you need a timezone string, not a number. I'm not really sure how that would work in this application since all datetime fields are stored in UTC and then need to be displayed in the user's local timezone Quote Link to comment https://forums.phpfreaks.com/topic/268029-help-with-strtotime/#findComment-1375515 Share on other sites More sharing options...
lemmin Posted September 5, 2012 Share Posted September 5, 2012 You need an operator between the return value of strtotime and your offset variable. The reason it works when you manually type that out is because the negative symbol is being parsed as the operator. Try this: <? $timeDiff = $_SESSION['DirectExaminerCompanyTimeZone'] * 3600; echo date('n-d-Y @ g:i a', strtotime($row['OrderTicketStatusDateTime']) + $timeDiff); ?> Quote Link to comment https://forums.phpfreaks.com/topic/268029-help-with-strtotime/#findComment-1375516 Share on other sites More sharing options...
Hobbyist_PHPer Posted September 5, 2012 Author Share Posted September 5, 2012 You need an operator between the return value of strtotime and your offset variable. The reason it works when you manually type that out is because the negative symbol is being parsed as the operator. Try this: <? $timeDiff = $_SESSION['DirectExaminerCompanyTimeZone'] * 3600; echo date('n-d-Y @ g:i a', strtotime($row['OrderTicketStatusDateTime']) + $timeDiff); ?> Yes, perfect, thank you very much for catching that Quote Link to comment https://forums.phpfreaks.com/topic/268029-help-with-strtotime/#findComment-1375518 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.