The time stamp of the MySQL time attribute and the conversion between datetime

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.