• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
gmt_to_local() returns incorrect date

[eluser]the real rlee[/eluser]
Hi guys,

I'm having weird issue with the date helper in CI. gmt_to_local() with correct timezone (UP10) is not showing the correct date, however PHP's gmdate IS showing the correct date.

What's possibly wrong here?

FYI Im using XAMPP on my local machine

How many minutes is the difference and is the time on your local machine correct?

[eluser]the real rlee[/eluser]
hmm does this matter (?)... php's gmdate() returns correct day. please explain Smile

[eluser]the real rlee[/eluser]
Ok, it seems gmt_to_local() is returning exactly 11 hours ahead of what it should be Sad Anyone got any ideas on how to fix this. Would really appreciate some help on this

[eluser]Myles Wakeham[/eluser]
Have you had a look at the source in date_helper.php to see what could be going on there? I believe there are differences in date handling with PHP depending on whether you are running on Windows or Linux, and a lot of it has to do with the date range that you are dealing with (ie. I believe under certain PHP versions, dates < 1970 on Windows are not supported?). Anyway the source code is right there. Add some statements in the helper to let you see what is going on, and it should tell you what the deal is.

I use it in my apps with XAMP on Windows and its working fine for me.


[eluser]the real rlee[/eluser]
Ok, im getting confused lol. Seems in config i can set time ref to be local or gmt. Obviously how i set this depends on what the server is already using yes? Do you know what Xammp is using?

[eluser]Myles Wakeham[/eluser]
Have you traced through your code and looked at what gmt_to_local() is doing? The code is really simple:

function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE)
    if ($time == '')
        return now();
    $time += timezones($timezone) * 3600;

    if ($dst == TRUE)
        $time += 3600;
    return $time;

Just trace through this and see what its doing. The answer to your question lies in that.


[eluser]Myles Wakeham[/eluser]
Also you can test to see what the default timezone on the server is set with the PHP command 'date_default_timezone_get'. That should tell you what your computer is assuming is the default timezone.


[eluser]the real rlee[/eluser]
Think i get it now... My problem lies in the fact I'm trying to convert a value, which is already local time, to local time again i.e. gmt + timezone!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.