mfallon Posted April 8, 2009 Share Posted April 8, 2009 I have the following code which displays when my users were last active. $date = date("d/m/y, H:i P ",mysql_result($result,$i,"users.timestamp")); I have used the P switch to show the timezone difference as all users are located in GMT but the server is not (US EST to be specific) and I want to be able to see clearly when the user last logged on. How can I get it to show the time in GMT? Do I need to set the timezone in the code when I put the timestamp in to the database, and / or when I retrieve it? I've been searching furiously for the information but can't find anything. Thanks in advance for your help. Matt Fallon Link to comment https://forums.phpfreaks.com/topic/153189-solved-display-timestamp-based-on-specific-time-zone/ Share on other sites More sharing options...
laffin Posted April 8, 2009 Share Posted April 8, 2009 before calling the date function set the timezone with date_default_timezone_set(); or put it in one of the global includes date_default_timezone_set("GMT"); See how that works Link to comment https://forums.phpfreaks.com/topic/153189-solved-display-timestamp-based-on-specific-time-zone/#findComment-804823 Share on other sites More sharing options...
mfallon Posted April 8, 2009 Author Share Posted April 8, 2009 Thanks laffin, much better, the only issue I am left with is that the time shown does not include the fact that we are no under daylight savings, is there a way to specify the location instead of GMT so that daylight savings can be taken in to account. Thanks, Matt Link to comment https://forums.phpfreaks.com/topic/153189-solved-display-timestamp-based-on-specific-time-zone/#findComment-804830 Share on other sites More sharing options...
laffin Posted April 8, 2009 Share Posted April 8, 2009 U can try adding the 'I' Parameter to the date format string I (capital i) Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise. u may also wish to look at supported timezones Link to comment https://forums.phpfreaks.com/topic/153189-solved-display-timestamp-based-on-specific-time-zone/#findComment-804840 Share on other sites More sharing options...
mfallon Posted April 8, 2009 Author Share Posted April 8, 2009 Got it to work as I required with the following; date_default_timezone_set("Europe/London"); This shows the current time based on current daylight savings status. Thanks very much for your help. Matt Link to comment https://forums.phpfreaks.com/topic/153189-solved-display-timestamp-based-on-specific-time-zone/#findComment-804856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.