bugmenot Posted July 29, 2015 Share Posted July 29, 2015 Hello sorry for the English if it's bad I m working in XAMPP localhost v1.8.2, and the PHP version is 5.4.4 first here is the script $user_req = mysql_query("SELECT regdate FROM users WHERE id='$user_id'"); if(mysql_num_rows($user_req)>0){ $user_info = mysql_fetch_array($user_req); echo date('d/m/Y H:i a',$user_info['regdate']); } and the sql query that I use mysql_query('insert into users (username, password, email, regdate) values ("'.$username.'", "'.$password.'", "'.$email.'", "'.time().'")') the problem is that if registration date is [ 03:25:45 ] the output look like this [ 05:25:45 ] I don't know from where the 2 hours come from , I've tried in another script, I even reinstall XAMPP, but didn't work... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/297546-why-the-time-add-2hours-in-php/ Share on other sites More sharing options...
requinix Posted July 29, 2015 Share Posted July 29, 2015 That output doesn't match up with your code. Are you saying you get actual output like "30/07/2015 05:25 am" when you expect to see "30/07/2015 03:25 am"? Quote Link to comment https://forums.phpfreaks.com/topic/297546-why-the-time-add-2hours-in-php/#findComment-1517726 Share on other sites More sharing options...
bugmenot Posted July 29, 2015 Author Share Posted July 29, 2015 (edited) yes, I know the the code does not match, it's just for showing the example Edited July 29, 2015 by bugmenot Quote Link to comment https://forums.phpfreaks.com/topic/297546-why-the-time-add-2hours-in-php/#findComment-1517727 Share on other sites More sharing options...
bugmenot Posted July 30, 2015 Author Share Posted July 30, 2015 no help Quote Link to comment https://forums.phpfreaks.com/topic/297546-why-the-time-add-2hours-in-php/#findComment-1517728 Share on other sites More sharing options...
QuickOldCar Posted July 30, 2015 Share Posted July 30, 2015 In your php.ini file set your date.timezone =(your timezone) http://www.php.net/manual/en/timezones.php Quote Link to comment https://forums.phpfreaks.com/topic/297546-why-the-time-add-2hours-in-php/#findComment-1517729 Share on other sites More sharing options...
bugmenot Posted July 30, 2015 Author Share Posted July 30, 2015 In your php.ini file set your date.timezone =(your timezone) http://www.php.net/manual/en/timezones.php didn't work ... Quote Link to comment https://forums.phpfreaks.com/topic/297546-why-the-time-add-2hours-in-php/#findComment-1517730 Share on other sites More sharing options...
mac_gyver Posted July 30, 2015 Share Posted July 30, 2015 because you haven't posted any actual output from your code, there's a chance that the error is in your interpretation of the result. also, unix timestamps are not reliable, since an actual conversion between different number systems is required to use them. the following is from mysql's own documentation for it's unix timestamp based functions - Note: If you use UNIX_TIMESTAMP() and FROM_UNIXTIME() to convert between TIMESTAMP values and Unix timestamp values, the conversion is lossy because the mapping is not one-to-one in both directions. For example, due to conventions for local time zone changes, it is possible for two UNIX_TIMESTAMP() to map two TIMESTAMP values to the same Unix timestamp value. why not just store a mysql DATETIME value? Quote Link to comment https://forums.phpfreaks.com/topic/297546-why-the-time-add-2hours-in-php/#findComment-1517733 Share on other sites More sharing options...
requinix Posted July 30, 2015 Share Posted July 30, 2015 yes, I know the the code does not match, it's just for showing the exampleSo the code was accurate and your output was just the example? Or was the output accurate and your code was the example? If it's that then we need to see that code. Quote Link to comment https://forums.phpfreaks.com/topic/297546-why-the-time-add-2hours-in-php/#findComment-1517734 Share on other sites More sharing options...
bugmenot Posted July 30, 2015 Author Share Posted July 30, 2015 (edited) here is an actual output from my code :: [ User since : 30/07/2015 05:25 am ] when I expect to see :: [ User since :30/07/2015 03:25 am ] $user_req = mysql_query("SELECT regdate FROM users WHERE id='$user_id'"); if(mysql_num_rows($user_req)>0){ $user_info = mysql_fetch_array($user_req); echo 'User since : ' . date('d/m/Y H:i a',$user_info['regdate']) . '<br/>'; } and here is date setting in php.ini [Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = Africa/Casablanca ; http://php.net/date.default-latitude ;date.default_latitude = 31.7667 ; http://php.net/date.default-longitude ;date.default_longitude = 35.2333 ; http://php.net/date.sunrise-zenith ;date.sunrise_zenith = 90.583333 ; http://php.net/date.sunset-zenith ;date.sunset_zenith = 90.583333 Edited July 30, 2015 by bugmenot Quote Link to comment https://forums.phpfreaks.com/topic/297546-why-the-time-add-2hours-in-php/#findComment-1517765 Share on other sites More sharing options...
requinix Posted July 30, 2015 Share Posted July 30, 2015 (edited) What does it show if you change the code to echo 'User since : ' . date('d/m/Y H:i a T',$user_info['regdate']) . '';("T" is the timezone date() is using) Edited July 30, 2015 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/297546-why-the-time-add-2hours-in-php/#findComment-1517793 Share on other sites More sharing options...
bugmenot Posted August 1, 2015 Author Share Posted August 1, 2015 01/08/2015 17:36 pm WEST Quote Link to comment https://forums.phpfreaks.com/topic/297546-why-the-time-add-2hours-in-php/#findComment-1517858 Share on other sites More sharing options...
mac_gyver Posted August 1, 2015 Share Posted August 1, 2015 the WEST abbreviation is correct for your time zone - date_default_timezone_set('Africa/Casablanca'); echo date_default_timezone_get() . ' => ' . date('e') . ' => ' . date('T'); results in this - Africa/Casablanca => Africa/Casablanca => WEST this suggests that your stored data is incorrect. what's the code that's storing the data? perhaps it is altering the value before storing it? Quote Link to comment https://forums.phpfreaks.com/topic/297546-why-the-time-add-2hours-in-php/#findComment-1517871 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.