I have many timestamp columns that I need to use with mixed timezones. The users timezone is set in the language I’m using for the front-end so I need MySQL to return a unix timestamp from a select *. Is there a way to turn off the auto formatting when fetching data from MySQL timestamp columns?
Share
YYYY-MM-DD HH:MM:SSis the default representation for timestamp columns in MySQL. I don’t believe you can change that on a global level.Two options:
Instead of doing a
SELECT *, doSELECT *, UNIX_TIMESTAMP(your_timestamp_column) AS your_timestamp, which will add a Unix-formattedyour_timestampcolumn to the results.Make a view (
CREATE VIEW) for each table that does the same thing, e.g.Then you can do
SELECT * FROM your_view;and get your Unix timestamp without adding anything to your queries.Reference: UNIX_TIMESTAMP