mysql中時間日期的處理

2021-06-19 22:15:02 字數 1834 閱讀 9615

1、

select  srcapid as apid,year(statdate) as datey,month(statdate) as datem,ticketflag as bstype,

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

型別 大小 位元組 格式最小值 最大值舉例 date 4yyyy mm dd 1000 01 01 9999 12 31 1973 12 30 time 3hh mm ss 838 59 59 838 59 59 15 30 00 datetime 8yyyy mm dd hh mm ss 1000...

Java中的時間日期處理

1 精確到毫秒 date 的文字 日期 2 精確到天 calendar 的文字 日期 3 精確到毫秒 date 的日期 文字 4 精確到天 calendar 的日期 文字 當然了 calendar也是可以精確到秒的,比如 set功能 2008年5月12日 星期一 14時28分04秒 calendar...

MySQL中的時間日期型別

mysql中共有5種時間日期型別 型別名稱 時間格式 取值範圍 mysql5.6.4之前儲存需求 位元組 mysql5.6.4開始儲存需求 位元組 year yyyy 1901 2155 11 date yyyy mm dd 1000 01 01 9999 12 333 time hh mm ss ...