手机看片精品高清国产日韩,色先锋资源综合网,国产哺乳奶水91在线播放,乱伦小说亚洲色图欧洲电影

thinkphp5 時(shí)間比較查詢

2019-04-01 01:27:03 11957

時(shí)間比較

使用where方法

where方法支持時(shí)間比較,例如:


// 大于某個(gè)時(shí)間

where('create_time','>','2019-1-1');

// 小于某個(gè)時(shí)間

where('create_time','<=','2019-1-1');

// 時(shí)間區(qū)間查詢

where('create_time','between',['2018-1-1','2019-1-1']);

第三個(gè)參數(shù)可以傳入任何有效的時(shí)間表達(dá)式,會自動識別你的時(shí)間字段類型,支持的時(shí)間類型包括timestamps、datetime、date和int。


使用whereTime方法

whereTime方法提供了日期和時(shí)間字段的快捷查詢,示例如下:


// 大于某個(gè)時(shí)間

Db::table('think_user')->whereTime('birthday', '>=', '1970-10-1')->select();

// 小于某個(gè)時(shí)間

Db::table('think_user')->whereTime('birthday', '<', '2000-10-1')->select();

// 時(shí)間區(qū)間查詢

Db::table('think_user')->whereTime('birthday', 'between', ['1970-10-1', '2000-10-1'])->select();

// 不在某個(gè)時(shí)間區(qū)間

Db::table('think_user')->whereTime('birthday', 'not between', ['1970-10-1', '2000-10-1'])->select();

時(shí)間表達(dá)式

還提供了更方便的時(shí)間表達(dá)式查詢,例如:


// 獲取今天的博客

Db::table('think_blog') ->whereTime('create_time', 'today')->select();

// 獲取昨天的博客

Db::table('think_blog')->whereTime('create_time', 'yesterday')->select();

// 獲取本周的博客

Db::table('think_blog')->whereTime('create_time', 'week')->select();   

// 獲取上周的博客

Db::table('think_blog')->whereTime('create_time', 'last week')->select();    

// 獲取本月的博客

Db::table('think_blog')->whereTime('create_time', 'month')->select();   

// 獲取上月的博客

Db::table('think_blog')->whereTime('create_time', 'last month')->select();      

// 獲取今年的博客

Db::table('think_blog')->whereTime('create_time', 'year')->select();    

// 獲取去年的博客

Db::table('think_blog')->whereTime('create_time', 'last year')->select();

如果查詢當(dāng)天、本周、本月和今年的時(shí)間,還可以簡化為:


// 獲取今天的博客

Db::table('think_blog')->whereTime('create_time', 'd')->select();

// 獲取本周的博客

Db::table('think_blog')->whereTime('create_time', 'w')->select();   

// 獲取本月的博客

Db::table('think_blog')->whereTime('create_time', 'm')->select();   

// 獲取今年的博客

Db::table('think_blog')->whereTime('create_time', 'y') ->select();

V5.0.5+版本開始,還可以使用下面的方式進(jìn)行時(shí)間查詢


// 查詢兩個(gè)小時(shí)內(nèi)的博客Db::table('think_blog')->whereTime('create_time','-2 hours')->select();


提交成功!非常感謝您的反饋,我們會繼續(xù)努力做到更好!

這條文檔是否有幫助解決問題?

非常抱歉未能幫助到您。為了給您提供更好的服務(wù),我們很需要您進(jìn)一步的反饋信息:

在文檔使用中是否遇到以下問題: