V
V
Vladimir2016-09-04 13:09:05
MySQL
Vladimir, 2016-09-04 13:09:05

How to change TIMESTAMP value?

Good day! I have a database that has a field with "TIMESTAMP" by default. And it saves the date in YYYYMMDDHHMMSS format, and I would like to change it to "TIMESTAMP(8)" YYYYMMDD. When I try to set the value, phpMyAdmin gives me an error.

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(8) NOT NULL DEFAULT CURRENT_TIMESTAMP' at line 1

Tell me how to change the value?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pcdesign, 2016-09-04
@MasterGerold

It can create an intermediate tmp table, for example, with the required fields and the correct format
. And then insert the values ​​​​in the desired format there.
DATE_FORMAT(column_name, '%Y%m%d')
Type,

INSERT INTO tmp ( ts8 )
SELECT  DATE_FORMAT(ts_name, '%Y%m%d')
FROM    table

Then delete the old table, and rename this one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question