newbeee Posted December 30, 2008 Share Posted December 30, 2008 i tried the following code but this seems to return the current date and time. the format i use in mysql is 0000-00-00 00:00:00 and would like to convert to this format... dd-mm-yyy hh:mm:ss echo gmdate("d M Y H:i", time($rows['created_on'])); can someone please help me out Quote Link to comment https://forums.phpfreaks.com/topic/138805-convert-date-from-us-to-uk-from-a-string-got-from-mysql/ Share on other sites More sharing options...
laPistola Posted December 30, 2008 Share Posted December 30, 2008 in your mysql query use date_format() ie SELECT name, date_format(`date`,'%d %m %y %H:%i') as date FROM table Quote Link to comment https://forums.phpfreaks.com/topic/138805-convert-date-from-us-to-uk-from-a-string-got-from-mysql/#findComment-725809 Share on other sites More sharing options...
flyhoney Posted December 30, 2008 Share Posted December 30, 2008 You probably want to do this: echo gmdate("d M Y H:i", strtotime($rows['created_on'])); Quote Link to comment https://forums.phpfreaks.com/topic/138805-convert-date-from-us-to-uk-from-a-string-got-from-mysql/#findComment-725810 Share on other sites More sharing options...
newbeee Posted December 30, 2008 Author Share Posted December 30, 2008 this is more likely the way i need to do it as i can not change the 'create_on' string as it is used later on in the script. but using this method you say did not work it seem to mess up the date and time to a random date and time. i am using mysql datetime as a default so it is stored in US format, when i get the data from the DB in to the string i need to have it converted to the GMT format. You probably want to do this: echo gmdate("d M Y H:i", strtotime($rows['created_on'])); Quote Link to comment https://forums.phpfreaks.com/topic/138805-convert-date-from-us-to-uk-from-a-string-got-from-mysql/#findComment-725851 Share on other sites More sharing options...
RussellReal Posted December 30, 2008 Share Posted December 30, 2008 what timezone is the UK and what timezone in the US are you trying to do.. if lets say UK is +0 GMT and you want the US timestamp to be -5GMT just do.. strtotime($rows['created_on']." -5 hours"); Quote Link to comment https://forums.phpfreaks.com/topic/138805-convert-date-from-us-to-uk-from-a-string-got-from-mysql/#findComment-725855 Share on other sites More sharing options...
PFMaBiSmAd Posted December 30, 2008 Share Posted December 30, 2008 http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_convert-tz Quote Link to comment https://forums.phpfreaks.com/topic/138805-convert-date-from-us-to-uk-from-a-string-got-from-mysql/#findComment-725876 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.