1

I am from India and My website server is located in UK. When ever I use the now() function in PHP, it takes the server time which is UK time. Also when I use the Query

"select * from tblAttendance where DATE(AttDate) =DATE(now())  Order by EmpID "

This takes the time from the Server, So for me to get the current date attendance I need to wait till 10:30 AM my time as only then its a new day as per the server time.

Any help would be great.

Thanks

Sree Aka
  • 29
  • 1
  • 5
  • What is the question? How to set the timezone correctly? https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html – chris85 Nov 16 '15 at 05:06
  • use "bool date_default_timezone_set ( string $timezone_identifier )" in php ti change the time zone http://php.net/manual/en/function.date-default-timezone-set.php and for mysql time check out bellow post http://stackoverflow.com/questions/930900/how-to-set-time-zone-of-mysql – Parag Chaure Nov 16 '15 at 05:06
  • @parag that will only affect the PHP time, mysql's time could still be off. – chris85 Nov 16 '15 at 05:07
  • @chris85, yes comment is update for mysql time – Parag Chaure Nov 16 '15 at 05:09
  • This might help you: http://stackoverflow.com/a/32872549/3283363 – Indrasinh Bihola Nov 16 '15 at 05:27

2 Answers2

0

You need date_default_timezone_set() to set timezone to set and get timezone

date_default_timezone_set()

Timezones

and store this time to database.

Get date from php and apply to mysql query as follows.

date_default_timezone_set('Asia/Kolkata');
$date=date('Y-m-d'); // current date
$q= mysql_query("select * from tblAttendance where DATE(AttDate) ='".$date."' Order by EmpID ");
Disha V.
  • 1,834
  • 1
  • 13
  • 21
  • Hi Thanks for the help But I am not sure whether I am doing the right thing, date_default_timezone_set('Asia/Kolkata'); $q= mysql_query("select * from tblAttendance where DATE(AttDate) =DATE(now()) Order by EmpID "); This Again has the same issue, Is there anything else I need to do – Sree Aka Nov 20 '15 at 02:59
0

Set timezone like this:

date_default_timezone_set('Asia/Kolkata');
Sanjay Kumar N S
  • 4,653
  • 4
  • 23
  • 38
  • Hi Thanks for the help But I am not sure whether I am doing the right thing, date_default_timezone_set('Asia/Kolkata'); $q= mysql_query("select * from tblAttendance where DATE(AttDate) =DATE(now()) Order by EmpID "); This Again has the same issue, Is there anything else I need to do – Sree Aka Nov 20 '15 at 02:58
  • now() is the mysql function. So you have to set the mysql server timezone as well by running this query. SET time_zone = "+05:30"; – Sanjay Kumar N S Nov 20 '15 at 04:58