加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

mysql时间函数之hour,minute,second用法

(2019-09-03 09:56:35)
分类: java知识点总结
语法

HOUR(time)

Returns the hour for time. The range of the return value is 0 to 23 for time-of-day values. However, the range of TIME values actually is much larger, so HOUR can return values greater than 23.

返回时间的小时。 对于一天时间值,返回值的范围是0到23。 但是,TIME值的范围实际上要大得多,所以HOUR可以返回大于23的值。


MINUTE(time)

Returns the minute for time, in the range 0 to 59.

返回时间分钟,范围为0到59。


SECOND(time)

Returns the second for time, in the range 0 to 59.

返回时间秒数,范围为0到59。



SELECT hour('12:13:14');                  # 12
SELECT hour('122:13:14');                 # 122
SELECT hour('12-13-14');                  # 0
SELECT hour('2008-09-10 12:13:14');       # 12
SELECT hour('2008-09-10 122:13:14');      # null
SELECT hour('2008-09-10 12-13-14');       # 12

SELECT minute('12:13:14');                # 13
SELECT minute('12:60:14');                # null
SELECT minute('12-13-14');                # 0
SELECT minute('2008-09-10 12:13:14');     # 13
SELECT minute('2008-09-10 122:13:14');    # null
SELECT minute('2008-09-10 12-13-14');     # 13

SELECT second('12:13:14');                # 14
SELECT second('12:13:60');                # null
SELECT second('12-13-14');                # 12
SELECT second('2008-09-10 12:13:14');     # 14
SELECT second('2008-09-10 122:13:14');    # null
SELECT second('2008-09-10 12-13-14');     # 14



sql语句中的应用:

if(timestampdiff(MINUTE,modify_time,now())>720


       if uid then
set mm=timestampdiff(day,ftm,curdate());
if mm>0 then
insert into user_count(userId,count,time) values(uid,dct,CURRENT_TIMESTAMP);
update A set dayCount=v_count,flag_time=CURRENT_TIMESTAMP where userId=uid;
else
update A set dayCount=dayCount+v_count,flag_time=CURRENT_TIMESTAMP where userId=uid;
end if;
end if;





0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有