Mysql關於時間的操作

2021-09-11 03:26:17 字數 2552 閱讀 3425

-- mysql查詢本季度

-- 今天

select * from ticket_order_detail where to_days(use_time) = to_days(now());

-- 7天

select *from ticket_order_detail  where date_sub(curdate(), interval 7 day) <= date( use_time)

-- 近30天

select *from ticket_order_detail  where date_sub(curdate(), interval 30 day) <= date( use_time)

-- 本月

select *from ticket_order_detail  where date_format(  use_time, '%y%m' ) = date_format( curdate( ) , '%y%m' )

-- 上一月

select *from ticket_order_detail  where period_diff( date_format( now( ) , '%y%m' ) , date_format(  use_time, '%y%m' ) ) =1

#查詢本季度資料

select * from `ticket_order_detail` where quarter(use_time)=quarter(now());

#查詢上季度資料

select * from `ticket_order_detail` where quarter(use_time)=quarter(date_sub(now(),interval 1 quarter));

#查詢本年資料

select * from `ticket_order_detail` where year(use_time)=year(now());

#查詢上年資料

select * from `ticket_order_detail` where year(use_time)=year(date_sub(now(),interval 1 year));

-- 查詢當前這週的資料

select name,submittime from enterprise where yearweek(date_format(submittime,』%y-%m-%d』)) = yearweek(now());

-- 查詢上週的資料

select name,submittime from enterprise where yearweek(date_format(submittime,』%y-%m-%d』)) = yearweek(now())-1;

-- 查詢當前月份的資料

select name,submittime from enterprise where date_format(submittime,』%y-%m』)=date_format(now(),』%y-%m』)

-- 查詢距離當前現在6個月的資料

select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();

-- 查詢上個月的資料

select name,submittime from enterprise where date_format(submittime,』%y-%m』)=date_format(date_sub(curdate(), interval 1 month),』%y-%m』)

select*from`user`wheredate_format(pudate,『%y%m『)=date_format(curdate(),『%y%m『) ;

select * from user where weekofyear(from_unixtime(pudate,』%y-%m-%d』)) = weekofyear(now())

select*

fromuser

wheremonth(from_unixtime(pudate,『%y-%m-%d『))=month(now())

select*

from[user]

whereyear(from_unixtime(pudate,『%y-%m-%d『))=year(now())

andmonth(from_unixtime(pudate,『%y-%m-%d『))=month(now())

select*

from[user]

-- wherepudatebetween上月最後一天

-- and下月第一天

where date(regdate) = curdate();

select * from test where year(regdate)=year(now()) and month(regdate)=month(now()) and day(regdate)=day(now())

select date( c_instime ) ,curdate( )

from `t_score`

where 1

limit 0 , 30

mysql 時間操作 mysql操作時間

select curdate 獲取當前日期 select last day curdate 獲取當月最後一天。select date add curdate interval day curdate 1 day 獲取本月第一天 select date add curdate day curdate ...

mysql中的時間例項 MySql 時間操作例項

select now 6 as 當前時間精確到微秒 select unix timestamp as 當前時間戳 unix timestamp 2018 1 1 as 轉換成時間戳 from unixtime 1523439700 as 時間戳轉datetime date format now y ...

關於日期時間的操作

時間格式過濾器 vue.filter formatdate data 用法 new date gettime math.round math.random 100001.math.random 結果為0 1間的乙個隨機數 包括0,不包括1 2.math.floor num 向下取整 3.math.r...