mysql how to convert varchar(10) to TIMESTAMP?
-
I have stored all the date into my database as varchar(10), now I want to converse them into TIMESTAMP. When I run sql ALTER TABLE `demo3` CHANGE `date` `date` TIMESTAMP NOT NULL it alert: #1292 - Incorrect datetime value: '1320534000' for column 'date' at row 1 BTW, All my date formart are 10 digital number.
-
Answer:
You should first change the timestamp to datetime and then can change the type of column. ALTER TABLE `demo3` MODIFY COLUMN `date` varchar(25); UPDATE `demo3` SET `date`= FROM_UNIXTIME(`date`); ALTER TABLE `demo3` CHANGE `date` `date` TIMESTAMP NOT NULL
fish man at Stack Overflow Visit the source
Other answers
You need to add a new column with the type you want, then update the table, converting the string to number for each row in an update statement. So Add your new timestamp column with a default of NULL Then run something similar to: UPDATE demo3 SET new_timestamp = CONVERT(date, signed) (You may need to try converting from unix timestamp and back again - see http://kitt.hodsden.org/mysql/converting_to_mysqls_timestamp_from_int11) Which should push the integers into the timestamp column. Then get rid of the original date column and rename the timestamp column.
dash
First you have to convert that unix timestamp format with the FROM_UNIXTIME function.
golimar
Related Q & A:
- How To Convert Pmd To Word Online?Best solution by pmd.afreecodec.com
- How to convert Oracle script to MySQL script?Best solution by Stack Overflow
- How to convert full date/time to timestamp?Best solution by Stack Overflow
- How to convert isbn 13 to isbn 10?Best solution by Stack Overflow
- How to convert a GMT timestamp to proper Date in PHP?Best solution by stackoverflow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.