[英]Date Ranges between 2 dates (Syntac)
This is driving me crazy!!!这真让我抓狂!!! Here is the code that I am trying to put data for the last 31 days between 2 dates, NOW and 31 days later.
这是我试图将过去 31 天的数据放在 NOW 和 31 天后的 2 个日期之间的代码。
This code does not work:此代码不起作用:
$now = date("Y-m-d");
$datetime = new DateTime($now);
$datetime->modify('+31 days');
$NEW_30 = $datetime->format('Y-m-d');
$get_time1ax = "select * from support_tickets WHERE start_date >= '".$now."' AND end_date <= '".$NEW_30."' ORDER BY problem_title ASC";
But this code does work?但是这段代码有效吗? Do not understand this.
不明白这个。
$get_time1ax = "select * from support_tickets WHERE start_date >= '2020-03-19' AND end_date <= '2020-04-19' ORDER BY problem_title ASC";
Notice the actual date is in the field and not a variable.请注意,实际日期在字段中,而不是变量。 Weird.
奇怪的。
Any help would be helpful.任何帮助都会有所帮助。
I am trying to put data for the last 31 days between [...] now and 31 days later.
我试图将过去 31 天的数据放在 [...] 现在和 31 天后。
You can do date arithmetics directly in the database:您可以直接在数据库中进行日期算术:
select *
from support_tickets
where start_date >= curent_date and end_date <= current_date + interval 31 day
Possibly, you mean 1 month when you say 31 days, so:可能,当您说 31 天时,您的意思是 1 个月,因此:
select *
from support_tickets
where start_date >= curent_date and end_date <= current_date + interval 1 month
try this:尝试这个:
$current_date = date("Y-m-d");
$current_date_plus_31 = date('Y-m-d',strtotime('+31 days',strtotime($current_date)));
this is how it works for me with today's date and in 31 days这就是我今天和 31 天后的工作方式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.