您的位置:首页 > 数据库 > MySQL

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: