Jump to content

Recommended Posts

Hello

sorry for the English if it's bad :sweat:

 

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 :confused:  , I've tried in another script, I even reinstall XAMPP, but didn't work...

Thanks :pirate:

Link to comment
https://forums.phpfreaks.com/topic/297546-why-the-time-add-2hours-in-php/
Share on other sites

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?

yes, I know the the code does not match, it's just for showing the example

So 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.

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 by bugmenot

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?

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.