TP6便捷快速查询日、月、年数据的方法
发表于:2021-07-19 10:12:30浏览:3837次
开发中有时会遇到按日、按周、按月等查询数据的问题,对此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为字段名。
推荐文章
- Unicode 14.0标准版本发布,新增 838 个字符,共计达 144697 个字符
- Element-plus,动态添加图标的方式
- 利用微软的Office Online实现Office文档在线预览功能
- PHP中如何将数组转换为JSON格式数据
- 使用table2excel实现layui数据表格导出复杂表头EXCEL
- 日常开发中,关于双token机制的介绍及双token的优点
- 82个常规的前端JavaScript方法封装(51~60)
- PHP8出来也已经有一段时间了 说说PHP8的新特性
- centos系统,宝塔面板SSL证书文件在哪里?
- PHP将透明图片(PNG)合并到JPG背景图片上,实现PNG透明的效果

