Convert date to Unix timestamp

Asked

Viewed 398 times

5

I have a table in a Mysql database that has a date column VARCHAR, guy 20-09-2017 and I need to migrate this column to a column bigint(8) using the date format timestamp unix.

How to do this?

2 answers

4


1

Follow the solution I used.

Converting from string to date:

Update `tabela` 
set date = STR_TO_DATE(date_text, '%d/%m/%Y')

Converting from date to Unix timestamp:

Update `tabela`
set date_unix = UNIX_TIMESTAMP('date');
  • 1

    In case, note that the solution is precisely what was posted in the other answer, is that it? It would be good to mark it as accepted to close the question.

  • The problem is when I asked the question I hadn’t registered yet. Now I can’t accept Maniero’s answer. Sorry by BO.

  • If this is the case, you can signal the site’s team to merge their posts, if they can determine which ones are really yours. This way I believe you could get the "lost" score back; as for what happened, stay calm. No need to apologize, it was just a recommendation for a matter of organizing the site.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.