如题:我想求小时数
需求是这样的:在时间段8:30-12:00和2:30-6:00内,求每一天的当前时间距离前面两个时间段结束时间的小时数。
意思就是:上午求当前时间距离12:00的小时数;下午求当前时间距离6:00的小时数。

解决方案 »

  1.   

    试试这个吧:
    select case when (time(now())>='08:30:00' and time(now())<='12:00:00') then hour(timediff('12:00:00', time(now()))) when (time(now())>='14:30:00' and time(now())<='18:00:00') then hour(timediff('18:00:00', time(now()))) end;不在这个时间段内,返回NULL值