waddledoo Posted December 13, 2011 Share Posted December 13, 2011 How would I change the current timezone used within a php script? The method I usually use, date_default_timezone_set() is undefined on my webhost, so I am trying to find another way. Link to comment https://forums.phpfreaks.com/topic/253047-change-timezone/ Share on other sites More sharing options...
joel24 Posted December 13, 2011 Share Posted December 13, 2011 //change timezone php putenv('TZ=Australia/Sydney'); and to change it in your mysql database //get offset, including daylight savings because mysql won't $currentOffset = "+".(date("Z") / 60 / 60).":00"; //timezone mysql $update_tz = @mysql_query("SET time_zone = '$currentOffset'") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/253047-change-timezone/#findComment-1297356 Share on other sites More sharing options...
waddledoo Posted December 13, 2011 Author Share Posted December 13, 2011 This code: <?php date_default_timezone_set('Canada/mountain'); //this is on my computer; on the webhost it is unnecessary echo date('H:i:s'); putenv('TZ=UTC'); echo "<br>"; echo date ('H:i:s'); ?> Is displaying this: 20:01:30 20:01:30 What am I doing wrong? EDIT: I don't know what the issue is on my own computer, but using the 'putenv' with the webhost works perfectly, thanks! Link to comment https://forums.phpfreaks.com/topic/253047-change-timezone/#findComment-1297358 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.