0

I have my server in America/Chicago, I am posting current time with data in one of my filed qu_time. I am from India,so I need Asia/Kolkata as timezone for insert current time in my database. I have tried many from stackflow but I am not success, Can anyone please suggest me what should I do for it ? My current query is like below

$upd_qry = "update tbl_quotes 
                set qu_status='".$_GET['status']."', qu_time=NOW()              
                where _quid='".$_GET['quotes_id']."'";
  $result=mysqli_query($mysqli,$upd_qry);

Thanks

1 Answers1

0

There are two ways to set the timezone and get its value. First, is to set it on php end using:

date_default_timezone_set('Asia/Kolkata');

and instead of using now(), use:

date('Y-m-d H:i:s')

to get current datetime in mysql datetime format.

Second, is to set on mysql server and use now() to get current datetime. To set the timezone on server, check this link, on this link there is an answer with 260 upvotes, follow it and every thing will be fine.

Note: Keep in mind that by setting the php timezone you cannot get the right datetime using now() function, as now() is a mysql function, it return the datetime according to mysql server's settings.

Community
  • 1
  • 1
Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59