Results 1 to 4 of 4

Thread: [RESOLVED] PHP time() gives a different time

  1. #1

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Resolved [RESOLVED] PHP time() gives a different time

    Hi guys

    This is the code:
    php Code:
    1. 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

    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:
    1. //include_config
    2.     mysql_connect ($db_host, $db_user, $db_pwd) or die(mysql_error());
    3.     mysql_selectdb ($db_database) or die(mysql_error());
    4.    
    5.     $a = time();
    6.     echo date( 'D, j M Y, g:i A' , $a);
    7.    
    8.     $result = mysql_query("SELECT NOW() as t") or die(mysql_error());
    9.     $row = mysql_fetch_array($result);
    10.     echo "<br />" . date( 'D, j M Y, g:i A' ,strtotime($row['t']));
    Last edited by akhileshbc; Oct 9th, 2011 at 05:17 AM. Reason: added webserver's test results

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  2. #2

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: PHP time() gives a different time

    Found the solution. The problem is because of the timezone.

    Solution:

    Click on the Wamp server icon.



    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"



    That's all !


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  4. #4

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [RESOLVED] PHP time() gives a different time

    Quote Originally Posted by Nightwalker83 View Post
    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.



    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width