MySQL date type and millisecond value convert each other

Source: Internet
Author: User

Sometimes it is necessary to convert a date type value to a millisecond value, and sometimes to convert a millisecond value to a date, in order to be more convenient to meet the needs of the query.

Now, create a new database table T_stu_info and insert the data into the tables

Use Test;show tables;create table T_stu_info (     ID int. NOT NULL PRIMARY key,     stu_name varchar),     stu_date Tim Estamp,     stu_age Int (3),     stu_sex varchar (5));    Insert into T_stu_info (id,stu_name,stu_date,stu_age,stu_sex) VALUES (' 1 ', ' Zhangsan ', ' 2000-12-12 12:30:00 ', ' 15 ', ' Man '), Commit;select * from T_stu_info;



1, date converted to millisecond value

Select Unix_timestamp (t.stu_date) from T_stu_info t



2, millisecond value converted to date

SELECT     from_unixtime (Unix_timestamp (t.stu_date),            '%y-%m-%d%h:%i:%s ') as Stu_datefrom    T_stu_info t



SELECT     from_unixtime (Unix_timestamp (t.stu_date),            '%y-%m-%d ') as Stu_datefrom    T_stu_info t


MySQL date type and millisecond value convert each other

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.