mysql時間加減函式為date_add()、date_sub()
定義和用法
date_add() 函式向日期新增指定的時間間隔。
date_sub() 函式向日期減少指定的時間間隔。
語法date_add(date,interval expr type)
date_sub(date,interval expr type)
date 引數是合法的日期表示式。
expr引數是您希望新增的時間間隔。
type 引數可以是下列值:
type 值
microsecond
second
minute
hour
dayweek
month
quarter
year
second_microsecond
minute_microsecond
minute_second
hour_microsecond
hour_second
hour_minute
day_microsecond
day_second
day_minute
day_hour
year_month
mysql 為日期增加乙個時間間隔:date_add()
set @dt = now();
select date_add(@dt, interval 1 day); - 加1天
select date_add(@dt, interval 1 hour); -加1小時
select date_add(@dt, interval 1 minute); - 加1分鐘
select date_add(@dt, interval 1 second); -加1秒
select date_add(@dt, interval 1 microsecond);-加1毫秒
select date_add(@dt, interval 1 week);-加1周
select date_add(@dt, interval 1 month);-加1月
select date_add(@dt, interval 1 quarter);-加1季
select date_add(@dt, interval 1 year);-加1年
加上30分鐘
update market_call_record c set c.connection_end_time = date_add(c.connection_start_time, interval 30 minute) ;
例:更新某個時間,每個時間加上乙個星期
update comment c set c.time = date_add(c.time, interval 7 day) ;
2. mysql 為日期減去乙個時間間隔:date_sub(),格式同date_add()類似
例子:更新某個時間,使每個時間減少乙個月
update comment c set c.time = date_sub(c.time, interval 1 month)
mysql 固定日期 mysql查詢指定日期
1.今天 select from hb contract in h where to days modify date to days now 2.昨天 select from hb contract in h where to days now to days modify date 1 3.近七...
mysql 獲取指定日期到指定日期 區間段的日期
第一種方法 cross join 就相當於mysql中的迴圈 cross join 把兩張表中的資料進行 n m的組合,即笛卡爾積 這裡的兩張表利用 union all都有5條資料,所以進行 cross join 後 就有25條資料 而指定的日期區間就會從這25條資料總產生 select curda...
mysql 查詢指定日期格式
mysql 查詢指定日期格式,使用 date format date,format 函式 select date format create date,y m d h i s as create date from tableselect date format a.submit time,y as...