MySQL now () change timezone
I use the following INSERT statement:
INSERT INTO messages SET `to` = '".$to."', `from` = '".$this->userid."', `title` = '".$title."', `message` = '".$message."', `created` = NOW()
However, it uses my server time (America / Montreal). I want the time zone of Asia (Asia / Calcutta)
Is this possible with the same query?
You would like to use the function CONVERT_TZ()in MySQL. It is based on the Olson database that your operating system uses.
Here is the documentation.
After you open the connection to MySQL, run the following as a query:
SET time_zone = timezone;
Then, all the functions you perform will be performed for this time zone for this connection (i.e., until you close the "link" to the database ".
, "" /. Tiemzone , .
http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html
$myDateTime = new DateTime('2012-05-23 17:01', new DateTimeZone('GMT'));
$myDateTime->setTimezone(new DateTimeZone('Asia/Kolkata'));
echo $myDateTime->format('Y-m-d H:i');
After making changes to the code above, for example, the desired format; you can use the variable $myDateTimeto insert into the database.