Tôi có ba ngày A, B và C.
A = 2013-08-10 10:00
B = 2013-08-10 12:00
C = 2013-08-10 10:22
Những gì tôi đang cố gắng làm là kiểm tra xem C có ở trong A và B không, nếu nó trả về đúng. Bất cứ ai có bất kỳ ý tưởng về cách làm điều này?
Tôi đã thử điều này mà không có may mắn
if [$time >= $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
Đã trả lời ngày 13 tháng 8 năm 2013 lúc 12:54Aug 13, 2013 at 12:54
Sử dụng mã sau để so sánh giá trị ngày trong PHP
$a = new DateTime["2013-08-10 10:00"];
$b = new DateTime["2013-08-10 12:00"];
$c = new DateTime["2013-08-10 10:22"];
if [$a < $c && $c < $b ] {
return true;
}
Đã trả lời ngày 13 tháng 8 năm 2013 lúc 13:03Aug 13, 2013 at 13:03
alok.kumaralok.kumaralok.kumar
3803 Huy hiệu bạc11 Huy hiệu đồng3 silver badges11 bronze badges
Sử dụng hàm strtotime.
$A = "2013-08-10 10:00";
$B = "2013-08-10 12:00";
$C = "2013-08-10 10:22";
if [strtotime[$C] > strtotime[$A] && strtotime[$C] < strtotime[$B]]{
echo "The time is between time A and B.";
} else {
echo "It is not between time A and B.";
}
Đã trả lời ngày 13 tháng 8 năm 2013 lúc 12:52Aug 13, 2013 at 12:52
1
Sử dụng lớp DateTime
:
$A = '2013-08-10 10:00';
$B = '2013-08-10 12:00';
$C = '2013-08-10 10:22';
$dateA = DateTime::createFromFormat['Y-m-d H:m', $A];
$dateB = DateTime::createFromFormat['Y-m-d H:m', $B];
$dateC = DateTime::createFromFormat['Y-m-d H:m', $C];
if [$dateA >= $dateB && $dateA = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
9 if [$time >= $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
0 if [$time >= $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
2 if [$time >= $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
4$a = new DateTime["2013-08-10 10:00"];
$b = new DateTime["2013-08-10 12:00"];
$c = new DateTime["2013-08-10 10:22"];
if [$a < $c && $c < $b ] {
return true;
}
4Output:
$A = strtotime[$A]; //gives value in Unix Timestamp [seconds since 1970]
$B = strtotime[$B];
$C = strtotime[$C];
if [[[$C < $A] && [$C > $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
5$A = strtotime[$A]; //gives value in Unix Timestamp [seconds since 1970]
$B = strtotime[$B];
$C = strtotime[$C];
if [[[$C < $A] && [$C > $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
6 $A = strtotime[$A]; //gives value in Unix Timestamp [seconds since 1970]
$B = strtotime[$B];
$C = strtotime[$C];
if [[[$C < $A] && [$C > $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
7 if [$time >= $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
5$A = strtotime[$A]; //gives value in Unix Timestamp [seconds since 1970]
$B = strtotime[$B];
$C = strtotime[$C];
if [[[$C < $A] && [$C > $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
6 $a = new DateTime["2013-08-10 10:00"];
$b = new DateTime["2013-08-10 12:00"];
$c = new DateTime["2013-08-10 10:22"];
if [$a < $c && $c < $b ] {
return true;
}
2 if [$time >= $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time strtotime[$A] && strtotime[$C] < strtotime[$B]]{
echo "The time is between time A and B.";
} else {
echo "It is not between time A and B.";
}
2 if [$time >= $date_start && $time strtotime[$A] && strtotime[$C] < strtotime[$B]]{
echo "The time is between time A and B.";
} else {
echo "It is not between time A and B.";
}
4 if [$time >= $date_start && $time strtotime[$A] && strtotime[$C] < strtotime[$B]]{
echo "The time is between time A and B.";
} else {
echo "It is not between time A and B.";
}
6$A = strtotime[$A]; //gives value in Unix Timestamp [seconds since 1970]
$B = strtotime[$B];
$C = strtotime[$C];
if [[[$C < $A] && [$C > $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
0 if [$time >= $date_start && $time strtotime[$A] && strtotime[$C] < strtotime[$B]]{
echo "The time is between time A and B.";
} else {
echo "It is not between time A and B.";
}
9 if [$time >= $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
9 if [$time >= $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
0 if [$time >= $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
2 if [$time >= $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
4$a = new DateTime["2013-08-10 10:00"];
$b = new DateTime["2013-08-10 12:00"];
$c = new DateTime["2013-08-10 10:22"];
if [$a < $c && $c < $b ] {
return true;
}
4Output:
12-03-26 is latest than 2011-10-24
5$A = strtotime[$A]; //gives value in Unix Timestamp [seconds since 1970]
$B = strtotime[$B];
$C = strtotime[$C];
if [[[$C < $A] && [$C > $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
6 $A = strtotime[$A]; //gives value in Unix Timestamp [seconds since 1970]
$B = strtotime[$B];
$C = strtotime[$C];
if [[[$C < $A] && [$C > $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
7$A = strtotime[$A]; //gives value in Unix Timestamp [seconds since 1970]
$B = strtotime[$B];
$C = strtotime[$C];
if [[[$C < $A] && [$C > $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
5 if [$time >= $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
6 $A = strtotime[$A]; //gives value in Unix Timestamp [seconds since 1970]
$B = strtotime[$B];
$C = strtotime[$C];
if [[[$C < $A] && [$C > $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
2$a = new DateTime["2013-08-10 10:00"];
$b = new DateTime["2013-08-10 12:00"];
$c = new DateTime["2013-08-10 10:22"];
if [$a < $c && $c < $b ] {
return true;
}
9 if [$time >= $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time = $date_start && $time strtotime[$A] && strtotime[$C] < strtotime[$B]]{
echo "The time is between time A and B.";
} else {
echo "It is not between time A and B.";
}
$A = strtotime[$A]; //gives value in Unix Timestamp [seconds since 1970]
$B = strtotime[$B];
$C = strtotime[$C];
if [[[$C < $A] && [$C > $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
9 if [$time >= $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
0 if [$time >= $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
2 if [$time >= $date_start && $time $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
4DateTime
8DateTime
9
if [$time >= $date_start && $time strtotime[$A] && strtotime[$C] < strtotime[$B]]{
echo "The time is between time A and B.";
} else {
echo "It is not between time A and B.";
}
9$a = new DateTime["2013-08-10 10:00"];
$b = new DateTime["2013-08-10 12:00"];
$c = new DateTime["2013-08-10 10:22"];
if [$a < $c && $c < $b ] {
return true;
}
4Output:
2012-11-24 is latest than 2011-03-26
$A = strtotime[$A]; //gives value in Unix Timestamp [seconds since 1970]
$B = strtotime[$B];
$C = strtotime[$C];
if [[[$C < $A] && [$C > $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
5$A = strtotime[$A]; //gives value in Unix Timestamp [seconds since 1970]
$B = strtotime[$B];
$C = strtotime[$C];
if [[[$C < $A] && [$C > $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
6 $A = strtotime[$A]; //gives value in Unix Timestamp [seconds since 1970]
$B = strtotime[$B];
$C = strtotime[$C];
if [[[$C < $A] && [$C > $B]] || [[$C > $A] && [$C < $B]] ]{
echo "Yes '$C' is between '$A' and '$B'";
}
7 if [$time >= $date_start && $time use a simple comparison operator to compare the dates. echo "$date1 is older than $date2" ; ?>