mysql中时间日期的处理

1、
select  SrcAPID as APID, year(statDate) as dateY, month(statDate) as dateM,TicketFlag as bsType,
sum(length) as applyCount,sum(case when msgstatus='DELIVRD' then length else 0 end) as successCount,
sum(case when MsgStatus is not null and msgstatus !='' and msgstatus not like 'UMCS:'
 and msgstatus!=' DRV:109' then length else 0 end) as submitCount
from rpt_calllist
 where  statDate>='2013-09-01 00:00:00.000' and  statDate<='2013-10-32 23:59:59.888'
and  TicketFlag='00' and Flag = 'MT' group by  APID
获取日期的年月:year(statDate),month(statDate)
case的用法:case when MsgStatus is not null and msgstatus !='' and msgstatus not like 'UMCS:'
 and msgstatus!=' DRV:109' then length else 0 end

2、
select Meetingroom_Id, DATE_SUB(Meeting_MAP_BeginTime,INTERVAL "15:0" MINUTE_SECOND) as Meeting_MAP_BeginTime,
DATE_ADD(Meeting_MAP_EndTime,INTERVAL "15:0" MINUTE_SECOND) as Meeting_MAP_EndTime
from m_meetinginfo where now()< Meeting_MAP_BeginTime or Meeting_Fact_EndTime is null
DATE_SUB() 函数从日期减去指定的时间间隔。
DATE_ADD() 函数在日期中添加或减去指定的时间间隔。
语法
 DATEADD(datepart,number,date)
date 参数是合法的日期表达式。number 是您希望添加的间隔数;对于未来的时间,此数是正数,对于过去的时间,此数是负数。

3、
(date_format(modify_time, '%Y-%m-%d %H:%i:%S') < date_add(now(),interval -120 minute))
(abs( TIMESTAMPDIFF(minute,a.Meeting_Map_EndTime,#beginTime#)) <= 15
例:SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01');
TIMESTAMPDIFF(interval,datetime_expr1,datetime_expr2)
返回日期或日期时间表达式datetime_expr1 和datetime_expr2the 之间的整数差。
其结果的单位由interval参数给出。interval的法定值同TIMESTAMPADD()函数说明中所列出的相同,
包括FRAC_SECOND、SECOND、 MINUTE、 HOUR、 DAY、 WEEK、 MONTH、 QUARTER或 YEAR。
如果datetime_expr1或datetime_expr2中有一个为空,那么返回的结果就为NULL


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值