mysql中时间日期的处理
2013-12-26 14:47
344 查看
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
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
相关文章推荐
- MySQL对日期时间类型的处理和限制
- MySQL之日期时间处理函数
- MySQL 的时间日期处理
- MySQL中日期和时间处理总结
- mysql日期时间加减处理
- MySQL学习笔记八:日期/时间的处理
- PHP日期处理,mysql按日期、时间查询
- mysql 日期时间处理函数
- MySQL之日期时间处理函数
- MySQL对日期时间类型的处理和限制
- mysql 日期时间处理函数
- MySQL日期和时间处理函数应用总结
- excel导入mysql(用PHP-ExcelReader 方法),日期时间出错的处理办法
- excel导入mysql(用PHP-ExcelReader 方法),日期时间出错的处理办法
- MySQL学习笔记八:日期/时间的处理
- mysql对日期时间的处理
- PHP日期处理,mysql按日期、时间查询
- mysql 处理时间日期
- mysql日期时间处理
- 【数据库】【mysql】 之 日期时间处理