Add 9 hours and 30 minutes behind my time
I have a mysql database table that g开发者_如何学编程ets the "datetime" column automatically filled when a user fills in the php form page.
$timestamp = datetime("Y-m-d H:i:s");
Trouble is, the database server is in the USA which is 9 hours 30 minutes behind my time.
Does anyone know a way to change this so that the 9 hours 30 minutes hours get added to the datetime?
To answer your question directly, you can use the following function in your select statement:
select date_add(datefield, interval 570 minute) from table
However, as stated in some of the comments it's best if you correct the problem from the source and update the timezone in your DBMS.
You could always just use date which has an argument for timezone. http://www.php.net/manual/en/function.date.php
There are several possibilities. See http://www.php.net/manual/en/ref.datetime.php for a list of DateTime-Functions. date_add and date_sub are good candidates to start with
date_default_timezone_set().
1) Set the correct timezone in the php.ini file.
2) Set the correct timezone in your DBMS ( MySQL timezone change? for MySQL)
This won't require you to add some weird parameters or constantly use the same functions in your scripts.
精彩评论