计算出今天是 PHP 给定日期之后的 x 天
我的数据库中有返回事件月/日/年数据点的数据。
我想做的是检查今天是否是我得到的月/日/年之后的 20 天。
到目前为止,我有这样的问题:
// Get date data
$day = $row['DAYOFMONTH(hike_date)'];
$year = $row['YEAR(hike_date)'];
$month = $row['MONTH(hike_date)'];
// Get today's date
$todays_date = date("Y-m-d");
// Create the date I am comparing with
$date_string = $year.'-'.$month.'-'.$day;
我的问题是如何比较它?比较两个日期时,格式重要吗?
谢谢!
I have data in my database that returns the month/day/year data points for events.
What I want to do is check whether today is 20 days after the month/day/year that I get.
So far I have something like:
// Get date data
$day = $row['DAYOFMONTH(hike_date)'];
$year = $row['YEAR(hike_date)'];
$month = $row['MONTH(hike_date)'];
// Get today's date
$todays_date = date("Y-m-d");
// Create the date I am comparing with
$date_string = $year.'-'.$month.'-'.$day;
My question is how do I compare it? And is the format going to matter in comparing the two dates?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将月/日/年解析为 DateTime:
添加 20 天:
与今天比较:
参见
date_create
。Parse the month/day/year into a DateTime:
Add 20 days to it:
Compare it with today:
See
date_create
.使用
strttime
是最简单的方法。Using
strttime
is the easiest method.使用
函数将您的日期转换为时间戳,您可以更轻松地比较它们
use
function which will convert your dates into timestamp and you can compare them easier
strtotime 做了神奇的事情
strtotime does magical things