Reputation: 23290
I want to put my country's time into reg_date
field in my db table. But now()
puts servers time. How to change now()
functions time to Azerbaijan (UTC +04.00)?
Upvotes: 1
Views: 4493
Reputation: 13614
NOW()
should return the timestamp in the current timezone as set on your system. If you can't change the timezone of the system itself, you might have to manipulate the time before you save it using PHP/Ruby/whatever, or you could opt to save the time in UTC using UNIX_TIMESTAMP()
.
Using PHP (5.3+), code to manipulate the timezone before INSERT
ing into the database might look like:
// .... some preceding stuff
$date = new DateTime();
$date->setTimezone(new DateTimeZone('Asia/Baku'));
$fdate = $date->format('Y-m-d H:i:s'); // same format as NOW()
$query = "INSERT INTO tbl (field, created_on) VALUES ('blah', '$fdate')";
mysqli_query($query);
// ... and so on
Upvotes: 5