Jump to content

echo date/time from a unix timestamp taking into account DST


ruraldev

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.