Convert date to Unix timestamp

3

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?

    
asked by anonymous 20.09.2017 / 14:35

2 answers

2
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')
    
20.09.2017 / 15:22
1

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');
    
21.09.2017 / 17:39