sKunKbad Posted May 18, 2016 Share Posted May 18, 2016 I am changing the name of one of the fields in my table: ALTER TABLE `users` CHANGE `user_date` `created_at` DATETIME NOT NULL; The old field, "user_date" is int(10) and storing time in epoch format. The new field is just a datetime field. Is it possible to modify this query so that the time is converted to datetime? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/301209-change-date-stored-as-epoch-to-datetime-when-altering-table/ Share on other sites More sharing options...
Solution requinix Posted May 18, 2016 Solution Share Posted May 18, 2016 I suspect doing that will try to interpret existing data as YYYYMMDDHHMMSS strings, not as Unix timestamps. Will definitely work: add the created_at column, UPDATE it using FROM_UNIXTIME(user_date), then drop user_date. Three statements. 1 Quote Link to comment https://forums.phpfreaks.com/topic/301209-change-date-stored-as-epoch-to-datetime-when-altering-table/#findComment-1533074 Share on other sites More sharing options...
sKunKbad Posted May 20, 2016 Author Share Posted May 20, 2016 I suspect doing that will try to interpret existing data as YYYYMMDDHHMMSS strings, not as Unix timestamps. Will definitely work: add the created_at column, UPDATE it using FROM_UNIXTIME(user_date), then drop user_date. Three statements. Yep, this is what I ended up doing. I was just curious if there might have been a one liner way. Quote Link to comment https://forums.phpfreaks.com/topic/301209-change-date-stored-as-epoch-to-datetime-when-altering-table/#findComment-1533106 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.