使用whereTime方法
whereTime('birthday', '>=', '1970-10-1')->select();
// 大於某個時間
whereTime('birthday', '<', '2000-10-1')->select();
// 小於某個時間
whereTime('birthday', 'between', ['1970-10-1', '2000-10-1'])->select();
// 時間區間查詢
whereTime('birthday', 'not between', ['1970-10-1', '2000-10-1'])->select();
// 不在某個時間區間
時間表達式
// 獲取今天的文章 Db::table('think_news') ->whereTime('create_time', 'today')->select(); // 獲取昨天的文章 Db::table('think_news')->whereTime('create_time', 'yesterday')->select(); // 獲取本周的文章 Db::table('think_news')->whereTime('create_time', 'week')->select(); // 獲取上周的文章 Db::table('think_news')->whereTime('create_time', 'last week')->select(); // 獲取本月的文章 Db::table('think_news')->whereTime('create_time', 'month')->select(); // 獲取上月的文章 Db::table('think_news')->whereTime('create_time', 'last month')->select(); // 獲取今年的文章 Db::table('think_news')->whereTime('create_time', 'year')->select(); // 獲取去年的文章 Db::table('think_news')->whereTime('create_time', 'last year')->select();
