Php 查找时间是否在定义的范围内
可能重复: 我正在尝试查找日期是否在定义的范围内。我正在使用以下代码:Php 查找时间是否在定义的范围内,php,Php,可能重复: 我正在尝试查找日期是否在定义的范围内。我正在使用以下代码: $apple='25 March'; $udate= date('d F',strtotime($apple)); echo $udate; $startDate='21 March'; $realStartDate= date('d F',strtotime($startDate)) ; echo $realStartDate; $endDate='19 Apri
$apple='25 March';
$udate= date('d F',strtotime($apple));
echo $udate;
$startDate='21 March';
$realStartDate= date('d F',strtotime($startDate)) ;
echo $realStartDate;
$endDate='19 April';
$realEndDate= date('d F',strtotime($endDate)) ;
if ($udate >= $realStartDate && $udate <= $realEndDate ) {
echo 'within tange';
}
else{
echo 'Not in range';
}
?>
我哪里出错了?像这样
if(strtotime($givendate) > strtotime('3/21/xxxx') && strtotime($givendata) < strtotime('4/19/xxxx')) {
// Its within range
}
您可以使用DateTime
如果格式为7月1日,则将其放入函数中
比较时间戳而不是字符串表示
if(strtotime($apple) < strtotime($endDate) && strtotime($apple) > strtotime($startDate)){
// All ok!
}
试试这个
if (strtotime($udate) >= strtotime($realStartDate) && strtotime($udate) <= strtotime($realEndDate) ) {
echo 'within tange';
}
else{
echo 'Not in range';
}
试试这个,它能用
<?php
$udate = '25 March';
$udateTimestamp = strtotime($udate);
$startDate = '21 March';
$startDateTimestamp = strtotime($startDate);
$endDate = '19 April';
$eEndDateTimestamp = strtotime($endDate);
if ($udateTimestamp >= $startDateTimestamp && $udateTimestamp <= $eEndDateTimestamp)
{
echo 'within tange';
}
else
{
echo 'Not in range';
}
?>
你是否履行了你的职责并进行了搜查?选择所有日期或范围,并将其存储在数组中,然后使用php inarray函数。您是否在mysql上研究了中间日期或此链接:为什么要将字符串转换为时间戳,然后返回到完全相同的字符串?3月2日是在3月11日之前还是之后?根据你的密码。。。之后。比较时间戳,而不是人类格式。它的格式为日-月,即:7月1日
if (strtotime($udate) >= strtotime($realStartDate) && strtotime($udate) <= strtotime($realEndDate) ) {
echo 'within tange';
}
else{
echo 'Not in range';
}
<?php
$udate = '25 March';
$udateTimestamp = strtotime($udate);
$startDate = '21 March';
$startDateTimestamp = strtotime($startDate);
$endDate = '19 April';
$eEndDateTimestamp = strtotime($endDate);
if ($udateTimestamp >= $startDateTimestamp && $udateTimestamp <= $eEndDateTimestamp)
{
echo 'within tange';
}
else
{
echo 'Not in range';
}
?>