mysql时间函数之hour,minute,second用法_前进的火车_新浪博客

语法

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;





  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值