Disabling Timestamp Formatting in MySQL

I have many timestamp columns that I need to use with mixed time zones. The user time zone is set in the language I use for the interface, so I need MySQL to return the unix timestamp from select *. Is there a way to turn off automatic formatting when retrieving data from MySQL timestamp columns?

+3
source share
2 answers

YYYY-MM-DD HH:MM:SSis the default view for timestamp columns in MySQL. I do not believe that you can change this globally.

Two options:

  • Instead SELECT *, do SELECT *, UNIX_TIMESTAMP(your_timestamp_column) AS your_timestamp, which adds your_timestampa Unix column to the results.

  • (CREATE VIEW) , , .

    CREATE VIEW your_view AS
      SELECT *, UNIX_TIMESTAMP(your_timestamp_column) AS your_unix_timestamp
      FROM your_table;
    

    SELECT * FROM your_view; Unix, .

: UNIX_TIMESTAMP

+4

.

UNIX_TIMESTAMP :

UNIX_TIMESTAMP (your_timestamp_column) your_table;

mysql . : http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_unix-timestamp

+1

Source: https://habr.com/ru/post/1724982/


All Articles