ruraldev Posted October 27, 2008 Share Posted October 27, 2008 I have unix timestamps in a mysql database which I extract and display on a website, it seems to always return the date/time using the DST of todays date rather than the date being echoed. For example UK DST changed this weekend so if I run a report from last week the time displayed is 1 hour earlier than expected. Can anyone point me in the direction of the way to get the correct time. Thanks in advance Gordon Link to comment https://forums.phpfreaks.com/topic/130266-echo-datetime-from-a-unix-timestamp-taking-into-account-dst/ Share on other sites More sharing options...
rhodesa Posted October 27, 2008 Share Posted October 27, 2008 are you using the date() function for displaying dates? if you run the following code, does it match the date/time/timezone you expect? echo date('r'); Link to comment https://forums.phpfreaks.com/topic/130266-echo-datetime-from-a-unix-timestamp-taking-into-account-dst/#findComment-675561 Share on other sites More sharing options...
PFMaBiSmAd Posted October 27, 2008 Share Posted October 27, 2008 The best way is to use a DATETIME field. The value you put into it will always be that value. A Unix timestamp must be converted to be used for almost any purpose and is subject to the rules that are applied when it is converted. Since you did not provide information on how you are converting it to be displayed, I will guess the php date() function? If so, try gmdate() instead. Link to comment https://forums.phpfreaks.com/topic/130266-echo-datetime-from-a-unix-timestamp-taking-into-account-dst/#findComment-675562 Share on other sites More sharing options...
ruraldev Posted October 27, 2008 Author Share Posted October 27, 2008 rhodesa, yes date('r') produced correct date etc for today PFMaBiSmAd, yes I was using php date but will give gmdate a try Thanks Gordon Link to comment https://forums.phpfreaks.com/topic/130266-echo-datetime-from-a-unix-timestamp-taking-into-account-dst/#findComment-675736 Share on other sites More sharing options...
ruraldev Posted October 27, 2008 Author Share Posted October 27, 2008 Tried gmdate but no luck. I suppose what I need to find is a way to work out the dst on the date the report is being run on ($startdate) rather than today, is this possible? Unfortunately the data in the mysql database is output from a 3rd party software program which I don't have the option of outputting a datetime value from. Thanks Gordon Link to comment https://forums.phpfreaks.com/topic/130266-echo-datetime-from-a-unix-timestamp-taking-into-account-dst/#findComment-675755 Share on other sites More sharing options...
rhodesa Posted October 27, 2008 Share Posted October 27, 2008 i guess i'm a little confused on the problem. Can you post a code sample with what you are getting and what you are expecting? Link to comment https://forums.phpfreaks.com/topic/130266-echo-datetime-from-a-unix-timestamp-taking-into-account-dst/#findComment-675756 Share on other sites More sharing options...
ruraldev Posted October 27, 2008 Author Share Posted October 27, 2008 Even only taking the start of the output I get _______________________ Shift Report for YJ07 EJF for 01-Oct-2008 Shift started at 06:47 and finished at 14:37 _______________________ The correct times should be 07:47 and 15:37 It has to be said I am very new to php and mysql although I managed to get everything else to work by trial and error I am certainly not skilled! [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/130266-echo-datetime-from-a-unix-timestamp-taking-into-account-dst/#findComment-675765 Share on other sites More sharing options...
PFMaBiSmAd Posted October 27, 2008 Share Posted October 27, 2008 After further review, gmdate() would not have fixed anything, unless the timestamps were produced using gmtime(), which they should be to avoid an DST problems. Is the DST database that php is using up to date? Your server clock changed but if the DST database does not know this, any conversion that is DST dependent will be one hour off. http://pecl.php.net/get/timezonedb http://pecl4win.php.net/ext.php/php_timezonedb.dll Link to comment https://forums.phpfreaks.com/topic/130266-echo-datetime-from-a-unix-timestamp-taking-into-account-dst/#findComment-675853 Share on other sites More sharing options...
ruraldev Posted October 27, 2008 Author Share Posted October 27, 2008 Checked the DST database and all is fine. Link to comment https://forums.phpfreaks.com/topic/130266-echo-datetime-from-a-unix-timestamp-taking-into-account-dst/#findComment-675862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.