MadDawgX Posted August 7, 2006 Share Posted August 7, 2006 Hey there,Im getting the date from a MySQL database like follow: [code]DATE_FORMAT(date, '%Y-%m-%d %r') as comdate[/code]That returns the time in the MySQL datase which is the Greenwhich time. Later on down the line I display this time. My question is, Is it possible to display the time so that it is the same as the user's timezone. So for example EST would -5 from the hour.- Thanx Quote Link to comment Share on other sites More sharing options...
Barand Posted August 7, 2006 Share Posted August 7, 2006 if user time is $x hours different from server time, tryecho date ('Y-m-d H:i:s', strtotime("+$x hours $dbtime")); Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 8, 2006 Share Posted August 8, 2006 @barand I tired that and I got some unintelligible string of numbers. Maybe I did something wrong.Anyways, I just wrote a function that will add time or subtract time based on the time zone. Now in this function the user_zone is the difference between their time and the servers local time. I hope that I did not waste my time writting this.The only problem that I see with this function is if it is the end or beging of the month the month does not change. I will continue working on this. If anyone has a fix for this and the potential leap year issue, please post it.[code]<?phpfunction format_time() { $system_date = "2006-08-07 09:54:30 PM"; $user_zone = "+ 4"; list($action, $subject) = explode(" ", $user_zone); list($date, $time, $ext) = explode(" ", $system_date); list($hr, $min, $sec) = explode(":", $time); list($year, $month, $d) = explode("-", $date); if (($action == "-") * ($ext == "AM")) { $a = floor($hr - $subject); if ($a < 0) { $b = floor($hr + 12); $hour = floor($b - $subject); $extention = "PM"; $day = floor($d - 1); }elseif ($hr == 12) { $hour = $a; $extention = "PM"; $day = floor($d - 1); }else{ $hour = $a; $extention = "AM"; } }elseif (($action == "+") * ($ext == "AM")) { $a = floor($hr + $subject); if ($a > 12) { $hour = floor($a - 12); $extention = "PM"; $day = floor($d + 1); }else{ $hour = $a; $extention = "AM"; } }elseif (($action == "-") * ($ext == "PM")) { $a = floor($hr - $subject); if ($a < 0) { $b = floor($hr + 12); $hour = floor($b - $subject); $extention = "AM"; $day = floor($d - 1); }else{ $hour = $a; $extention = "PM"; } }elseif (($action == "+") * ($ext == "PM")) { $a = floor($hr + $subject); if ($a > 12) { $hour = floor($a - 12); $extention = "AM"; $day = floor($d + 1); }else{ $hour = $a; $extention = "PM"; } }else{ $hour = $hr; $extention = $ext; } $result = '' . $year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $min . ':' . $sec . ' ' . $extention . ''; return $result;}$time = format_time();echo "$time"; ?>[/code]Good Luck,Tom Quote Link to comment 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.