One, datetime conversion to timestamp
Scenario One: Cast field type
1 Use' NEC ';2 SETSql_safe_updates=0;3 ALTER TABLE' Usr_user_info 'ChangeCOLUMN' Registertime ' registertime 'BIGINT( -) not NULLCOMMENT'Registration Time' ,4 ALTER TABLE ' usr_user_info ' ChangeCOLUMN' Lastlogintime ' lastlogintime 'BIGINT( -)NULL DEFAULT NULLCOMMENT'Last logon time' ;5 UPDATE' Usr_user_info 'SET' Lastlogintime '=unix_timestamp (' lastlogintime ');6 UPDATE' Usr_user_info 'SET' Registertime '=Unix_timestamp (' Registertime ');
Scenario Two: Adding temporary columns
1 --2 --table alter for Usr_user_info3 --4 /*Add Field*/5 Use' NEC ';6 ALTER TABLE' Usr_user_info 'ADD COLUMNTempregistertimeBIGINT( -)NULL ;7 ALTER TABLE' Usr_user_info 'ADD COLUMNTemplastlogintimeBIGINT( -)NULL ;8 9 /*make time conversions, and copy columns*/Ten UPDATEUsr_user_infoSETTempregistertime=Unix_timestamp (registertime); One UPDATEUsr_user_infoSETTemplastlogintime=Unix_timestamp (lastlogintime); A - /*Delete an existing field*/ - ALTER TABLEUsr_user_info the DROPRegistertime,DROPLastlogintime; - - /*Update Temporary field name*/ - ALTER TABLEUsr_user_info Change Tempregistertime registertimeBIGINT( -) not NULLCOMMENT'Registration Time'; + ALTER TABLEUsr_user_info Change Templastlogintime lastlogintimeBIGINT( -) COMMENT'Last logon time';
Second, timestamp converted to datetime
This Google a bunch of tutorials, mainly related to the ' From_unixtime (registertime) ' This conversion function, not detailed in detail the
The time stamp of the MySQL time attribute and the conversion between DateTime