php查询本年的数据的方法:1、通过date获取本年时间;2、运行查询语句“$result = $db->where($where)->select();”即可。
本文操作环境:Windows7系统、thinkphp v5.1版、Dell G3电脑。
php怎么查询本年的数据?
thinkphp查询当天,本周的,本月的,本年的数据
代码如:
//当天时间 $where['time'] = array( array('egt',strtotime(date('Y-m-d',time())), array('lt',strtotime(date('Y-m-d',time())).'+1 day') ); // 本周时间 $where['time'] = array( array('egt',strtotime(date('Y-m-d',time())).'-'.date('w',time()).' day'), array('lt',strtotime(date('Y-m-d',time())).'+1 week -'.date('w',time()).' day'); ); // 本月时间 $where['time'] = array( array('egt',strtotime(date('Y-m',time()))), array('lt',strtotime(date('Y-m',time()).'+1 month')) ); // 本年时间 $where['time'] = array( array('egt',strtotime(date('Y',time()))), array('lt',strtotime(date('Y',time()).'+1 year')) );
上面是查询条件,直接运用到查询语句就可以了
$result = $db->where($where)->select();
更正下上面的那个 本年 查询时间
$where['time'] = array( array('egt',strtotime(date('Y-01-01',time())), array('lt',strtotime(date('Y-01-01',time()).'+1 year')) );
修复版
//昨天时间 $yesterday['addtime'] = array( array('egt',strtotime(date('Y-m-d',time()).' -1 day')), array('lt',strtotime(date('Y-m-d',time()))) ); //当天时间 $day['addtime'] = array( array('egt',strtotime(date('Y-m-d',time()))), array('lt',strtotime(date('Y-m-d',time()).' +1 day')) ); // 本月时间 $month['addtime'] = array( array('egt',strtotime(date('Y-m',time()))), array('lt',strtotime(date('Y-m',time()).' +1 month')) ); // 本周时间 $week['addtime'] = array( array('egt',strtotime(date('Y-m-d',time()).'-'.date('w',time()).' day')), array('lt',strtotime(date('Y-m-d',time()).'+1 week -'.date('w',time()).' day')) );
推荐学习:《PHP视频教程》《最新的10个thinkphp视频教程》
以上是php怎么查询本年的数据的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。