I have a table in a MySQL database that has a date column VARCHAR
, type 20-09-2017
and I need to migrate this column to a bigint(8)
column that uses the Unix date format timestamp
.
How to do this?
I have a table in a MySQL database that has a date column VARCHAR
, type 20-09-2017
and I need to migrate this column to a bigint(8)
column that uses the Unix date format timestamp
.
How to do this?
UNIX_TIMESTAMP('2017-09-20 00:00:00')
>
If it is in another format, it has to be formatted before:
STR_TO_DATE('20-09-2017', '%d-%m-%Y')
Here is the solution I used.
Converting string to date:
Update 'tabela'
set date = STR_TO_DATE(date_text, '%d/%m/%Y')
Converting date to unix timestamp:
Update 'tabela'
set date_unix = UNIX_TIMESTAMP('date');