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