lynxus Posted September 4, 2011 Share Posted September 4, 2011 Hi Guys.. How can I change a date on the fly ? Everything is UTC on my server. How can I change a date to something else on the fly? Ie: $timezone = "cet"; $datetime = "2011-09-04 19:53:00"; echo $datetime($timezone); So I can give it a datetime and have it echo the datetime as if it were in the other timezone? Thanks Graham Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/ Share on other sites More sharing options...
voip03 Posted September 4, 2011 Share Posted September 4, 2011 check this link http://php.net/manual/en/function.date-default-timezone-set.php Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1265402 Share on other sites More sharing options...
voip03 Posted September 4, 2011 Share Posted September 4, 2011 strtotime http://php.net/manual/en/function.strtotime.php Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1265404 Share on other sites More sharing options...
lynxus Posted September 4, 2011 Author Share Posted September 4, 2011 I did think of " date_default_timezone_set('America/Los_Angeles');" However, Does this now change the timezone of the script? I dont want this. i want the script to stay in UTC however I want to be able to echo a date through a function that turns the inputted date into whateever datetime i ask for ? ( im not sure how strtotime will fix this issue? Can I punt a timezone to it? Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1265406 Share on other sites More sharing options...
voip03 Posted September 4, 2011 Share Posted September 4, 2011 What method are you using to find the time zone? Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1265416 Share on other sites More sharing options...
lynxus Posted September 4, 2011 Author Share Posted September 4, 2011 None currently ( Im assuming the data is correct in the DB ) I get dates from the database ( thats saved as UTC ) Id like to convert some dates on the fly to other timezones ( so i can display datetimes in other peoples locales ) I hope that makes sense? Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1265418 Share on other sites More sharing options...
voip03 Posted September 4, 2011 Share Posted September 4, 2011 Handling timezone conversion with PHP DateTime http://blog.boxedice.com/2009/03/21/handling-timezone-conversion-with-php-datetime/ Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1265426 Share on other sites More sharing options...
voip03 Posted September 4, 2011 Share Posted September 4, 2011 <?php $myDateTime = new DateTime('2011-09-04 23:05', new DateTimeZone('GMT')); $myDateTime->setTimezone(new DateTimeZone('America/New_York')); echo $myDateTime->format('Y-m-d H:i'); ?> Combination of the ‘select’ and ‘function’ will enable you to select ‘time zone’. Then you can manipulate the above code. Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1265451 Share on other sites More sharing options...
lynxus Posted September 4, 2011 Author Share Posted September 4, 2011 Cheers man, Ill give it a try in the morning and let yall know. Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1265454 Share on other sites More sharing options...
lynxus Posted September 5, 2011 Author Share Posted September 5, 2011 As promised, I tried it and it works perfectly. Thanks very much. -Graham Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1265742 Share on other sites More sharing options...
lynxus Posted September 5, 2011 Author Share Posted September 5, 2011 Is there a list of what can be put into this field: $myDateTime->setTimezone(new DateTimeZone('America/New_York')); I cant seem to find a definitive one Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1265747 Share on other sites More sharing options...
voip03 Posted September 5, 2011 Share Posted September 5, 2011 Full List http://php.net/manual/en/timezones.php Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1265749 Share on other sites More sharing options...
lynxus Posted September 5, 2011 Author Share Posted September 5, 2011 Ah ha, perfect.. ( Couldn't find that page anywhere ) Thanks again. -G Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1265762 Share on other sites More sharing options...
voip03 Posted September 5, 2011 Share Posted September 5, 2011 Thank you and good luck. Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1265764 Share on other sites More sharing options...
soltek Posted December 16, 2011 Share Posted December 16, 2011 Sorry for being an undertaker, but I dont think my question needs a new topic. So, does this function includes the 'daylight saving time' thing? Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1298338 Share on other sites More sharing options...
xyph Posted December 16, 2011 Share Posted December 16, 2011 It should, for those timezones that have DST. Further reading about the DateTime object http://laughingmeme.org/2007/02/27/looking-at-php5s-datetime-and-datetimezone/ Link to comment https://forums.phpfreaks.com/topic/246419-change-a-date-to-a-different-date-based-on-timezone/#findComment-1298344 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.