TP6便捷快速查询日、月、年数据的方法
发表于:2021-07-19 10:12:30浏览:4533次
开发中有时会遇到按日、按周、按月等查询数据的问题,对此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为字段名。
推荐文章
- vue微信站history模式微信自定义分享
- PHP快速查找value所在数组的索引值
- 微软宣布Windows 11将于2021年10月5日上市
- 谷歌Chrome浏览器v101稳定版发布 支持FedCM和优先级提示等新功能
- ref, toRef, toRefs,reactive, defineComponent, computed, unref, toRaw, watchEffect, onUpdated 10个VUE3前端API总结
- 普通OA办公系统的详细产品功能介绍
- 82个常规的前端JavaScript方法封装(11~20)
- 国产开源操作系统 深度操作系统deepin 23 Preview发布
- 用Prismjs给勾股博客的文章模块增加代码高亮功能
- 开源的OA办公系统 — 勾股OA4.09.10 发布

