[RESOLVED] PHP time() gives a different time
Hi guys :wave:
This is the code:
php Code:
echo date( 'D, j M Y, g:i A' , $time());
Output:
Code:
Sun, 9 Oct 2011, 9:58 AM
My System time:
Code:
Sun, 9 Oct 2011, 3:28 PM
How could we resolve this issue ?
I have tested in mySQL by inserting a record using mySQL's "NOW()" function. That's works correctly according to my system time. But in PHP, it is not !
I'm using WAMP server 2.
Thanks :wave:
Edit:
Tested on my webserver:
Code:
Sun, 9 Oct 2011, 5:14 AM --> php's time()
Sun, 9 Oct 2011, 5:14 AM --> sql's now()
Code used:
php Code:
//include_config
mysql_connect ($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_selectdb ($db_database) or die(mysql_error());
$a = time();
echo date( 'D, j M Y, g:i A' , $a);
$result = mysql_query("SELECT NOW() as t") or die(mysql_error());
$row = mysql_fetch_array($result);
echo "<br />" . date( 'D, j M Y, g:i A' ,strtotime($row['t']));
Re: PHP time() gives a different time
Found the solution. The problem is because of the timezone. :)
Solution:
Click on the Wamp server icon.
http://www.vbforums.com/
Click on the PHP. Then, click php.ini
The "php.ini" file will be opened in Notepad. Use "Find" tool (ctrl + F) to search for "date.timezone".
It would show the search result at this part:
Code:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = UTC
Change the "UTC" to "Asia/Calcutta" (that's my timezone - India)
That is:
Code:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Asia/Calcutta"
Save the file. Then, click on "Restart All Services"
http://www.vbforums.com/
That's all ! :)
:wave:
Re: [RESOLVED] PHP time() gives a different time
Yeah, I had the same problem on my website with the time not displaying correctly for my time zone.
Re: [RESOLVED] PHP time() gives a different time
Quote:
Originally Posted by
Nightwalker83
Yeah, I had the same problem on my website with the time not displaying correctly for my time zone.
My webserver is also displaying in different timezone. I haven't changed it !
What I changed is the issue with the MySQL NOW() function & PHP's time() function showing different time values on my same pc. PHP's timezone was the problem. MySQL works correctly with my local system time.
:wave: