当前位置: 移动技术网 > IT编程>数据库>Mysql > MySQL5.7: datetime

MySQL5.7: datetime

2018年11月16日  | 移动技术网IT编程  | 我要评论
-- 当前日期时间 select now(); select now(3);-- 保留3为毫秒数 SELECT NOW(6); -- 保留6为毫秒数 -- 当前日期和时间 至秒 select current_timestamp; select current_timestamp(3); select... ...
-- 当前日期时间
 select now();
 select now(3);-- 保留3为毫秒数
 
 select now(6); -- 保留6为毫秒数
 -- 当前日期和时间 至秒
 select current_timestamp; 
 select current_timestamp(3);
 select current_timestamp(6); 
 
 -- 当前日期,不包括时间
 
 select curdate();
 -- 当前时间
 select curtime();
 
 select date_format('2010-12-01 06:03:16.233999','%y-%m-%d %t:%f');
 
select date_format('2010-12-01 07:03:16','%y-%m-%d %h:%i:%s');

 select timestampadd(hour, -8, '2008-08-08 12:00:00');  
 select date_add('2008-08-08 12:00:00', interval -8 hour); 
 
 select get_format(date,'iso');
 select get_format(datetime,'iso');
 select period_diff(200808, 200801);
 select timestampdiff(year,'2002-05-01','2001-01-01');
 -- 
 drop table datetest;
 
 
 create table `datetest` (
`time_id`  int primary key auto_increment  comment '自動增長id',
`coaction` nvarchar(100) null default '', 
`createdate` timestamp(3) not null default current_timestamp(3), -- 保留3为毫秒数
`createdate2` datetime(3) not null default now(3),
`createdate3` timestamp(6) not null default current_timestamp(6),  --  current_timestamp on update current_timestamp
`createdate4` datetime(6) not null default now(6)  -- 保留6为毫秒数
) engine=innodb default charset=utf8 comment='时间格式测试' auto_increment=1;

select * from datetest;

insert into datetest(coaction) values('geovindu,涂聚文');

  

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网