0

I made a table like this:

CREATE TABLE options(
  id MEDIUM INT NOT NULL AUTO_INCREMENT,
  email VARCHAR(254) NOT NULL,
  created_at DATETIME DEFAULT NULL,
  PRIMARY KEY(id)
);

however.. after inserting a value like:

INSERT INTO options VALUES(0,'test@test.com',CURRENT_TIMESTAMP)

I got the created_at column with this value : 10:29 but right now the time is 16:29.

I believe that's because the server/db is located in the US and I'm in Brazil.

Is there a way to get my current time when inserting values into the table?

Onilol
  • 1,315
  • 16
  • 41
  • 2
    This may help a bit: http://dba.stackexchange.com/questions/20217/mysql-set-utc-time-as-default-timestamp – Siyual Feb 05 '16 at 18:44
  • you should use the `TIMESTAMP` data type because `TIMESTAMP` support `time_zone` http://stackoverflow.com/questions/409286/should-i-use-field-datetime-or-timestamp – Vipin Jain Feb 05 '16 at 18:57
  • 1
    Why not make the table definition `created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP` so [it does what you want](http://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html) all by itself? Then when you `SELECT`, use [`CONVERT_TZ()`](http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_convert-tz). – miken32 Feb 05 '16 at 20:04

0 Answers0