日期范围介于2个日期之间(Syntac)

时间:2020-03-20 16:54:33

标签: php mysql date

这让我发疯了!!! 这是我正在尝试在两个日期(现在和31天后)之间的最后31天放入数据的代码。

此代码不起作用:

Select  743818 teacherPersonID, 'STUTZ, DOUGLAS' teacherDisplay, 'FT' personnelStatus, 1.0 ftePosition, 'Other' dept, 'INTRO TO COMPUTER SCIENCE, STUDENT ASST' course_name, 28 ttlStudents, 4 termSeq, 'course1' courseName, 'students1' courseStudents
Into    #teacherCourses
UNION 
Select  743818, 'STUTZ, DOUGLAS', 'FT', 1.0, 'Math', 'ALGEBRA 3, MATH 115 KSU COLLEGE ALGEBRA', 30, 4, 'course2', 'students2'
UNION 
Select  743818, 'STUTZ, DOUGLAS', 'FT', 1.0, 'Math', 'STUDENT ASST, ADVANCED GEOMETRY', 24, 4, 'course3', 'students3'
UNION 
Select  743818, 'STUTZ, DOUGLAS', 'FT', 1.0, 'Other', 'STUDENT ASST, ADVANCED GEOMETRY', 24, 4, 'course3', 'students3'
UNION 
Select  743818, 'STUTZ, DOUGLAS', 'FT', 1.0, 'Math', 'ADVANCED GEOMETRY', 25, 4, 'course4', 'students4'
UNION 
Select  743818, 'STUTZ, DOUGLAS', 'FT', 1.0, 'Math', 'MATH 115 KSU COLLEGE ALGEBRA, ALGEBRA 3', 21, 4, 'course6', 'students6'
UNION 
Select  743818, 'STUTZ, DOUGLAS', 'FT', 1.0, 'Math', 'ALGEBRA 3, MATH 115 KSU COLLEGE ALGEBRA', 19, 4, 'course7', 'students7'

但是此代码有效吗?不明白这一点。

$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";

请注意,实际日期在字段中,而不是变量。奇怪的。

任何帮助都会有所帮助。

2 个答案:

答案 0 :(得分:2)

我正在尝试放置从现在到31天之间的最后31天的数据。

您可以直接在数据库中进行日期算术:

select * 
from support_tickets 
where start_date >= curent_date and end_date <= current_date + interval 31 day

可能的意思是说31天为1个月,所以:

select * 
from support_tickets 
where start_date >= curent_date and end_date <= current_date + interval 1 month

答案 1 :(得分:-1)

尝试一下:

$current_date = date("Y-m-d");
$current_date_plus_31 = date('Y-m-d',strtotime('+31 days',strtotime($current_date)));

这是今天的日期和31天后对我的工作方式