Here is my PHP code, it is working in localhost but when I am uploading on server it is not working. It is taking 1 day before data from database. and i am using timestamp as entry_time
<?php
require_once('connection.php');
$id=$_SESSION['SESS_MEMBER_ID'];
$query = mysql_query("select count(*) as Unread3 from s_daily_reporting where (mem_id='$id')&&(entry_time >= DATE_SUB(CURRENT_DATE(), INTERVAL 0 DAY))");
$data2= mysql_fetch_array($query);
echo $sum=8-$data2['Unread3'];
?>
You have to add the date default time of your country at the starting otherwise it will consider the standard time.
Example for india date_default_timezone_set('Asia/Kolkata');
. You can check for your country default time in google and add that at the starting
CURRENT_DATE()
already gives you the current date at midnight. If you want records from the same day, you don't need to subtract anything
entry_time >= DATE_SUB(CURRENT_DATE(), INTERVAL 0 DAY)
Can simply be
entry_time >= CURRENT_DATE()
it is working in localhost but when i am uploading on server it is not working it taking 1 day before data from database
Whether you're on localhost or live should make no difference to your results. If you confirm that the code works locally, then the problem is likely that entry_time
was stored with a timezone offset that is different from the server's current timezone. This is particularly likely if the data was built on another server and then transferred to the current one, or if the application that saved the data connected to the MySQL server from a remote location. Either way when the server compares entry_time
to CURRENT_DATE()
, it cannot get reliable results because it thinks that the two are from the same timezone.
To fix this, you should probably set the server's timezone when you connect. Once you've connected, run the following query before doing any time operations (adjust for your timezone offset):
SET timezone = '+0:00'