TP6便捷快速查询日、月、年数据的方法
发表于:2021-07-19 10:12:30浏览:4426次
开发中有时会遇到按日、按周、按月等查询数据的问题,对此TP自带有对应的查询方式,方便快捷,这里记录一下。
// 获取当日的数据
Db::table('table')->whereTime('create_time', 'today')->select();
// 获取昨天的数据
Db::table('table')->whereTime('create_time', 'yesterday')->select();
// 获取本周的数据
Db::table('table')->whereTime('create_time', 'week')->select();
// 获取上周的数据
Db::table('table')->whereTime('create_time', 'last week')->select();
// 获取本月的数据
Db::table('table')->whereTime('create_time', 'month')->select();
// 获取上月的数据
Db::table('table')->whereTime('create_time', 'last month')->select();
// 获取今年的数据
Db::table('table')->whereTime('create_time', 'year')->select();
// 获取去年的数据
Db::table('table')->whereTime('create_time', 'last year')->select();PS:create_time为字段名。
推荐文章
- Thinkphp6集成JWT API接口引入token
- xm-select,一个前端的多选解决方案
- PHP中的word文档生成与处理库PHPWord的基本使用
- PHP判断网站的访问来源是否是蜘蛛
- Windows11激活码
- 用phpqrcode轻松生成二维码,可自带logo
- ref, toRef, toRefs,reactive, defineComponent, computed, unref, toRaw, watchEffect, onUpdated 10个VUE3前端API总结
- PHP合并数组的4种常见方法
- 微软发布首个 Windows 11 ISO 版本 新的浏览器大战又要开始?
- Layui的table模块导出所有数据,无需修改前后端代码

