Welcome Guest, Not a member yet? Register   Sign In
Comparison Operators >= in Control Structures why false?
#7

(04-07-2019, 08:43 AM)skunkbad Wrote: PHP has no way of knowing that your dates are dates. There are a number of ways you could handle it, but the simplest would be to wrap your dates in strtotime()


PHP Code:
$date  '2019-04-07';

$date1 '2019-04-01';
$date2 '2019-04-15';
$date3 '2019-04-16';
$date4 '2019-04-30';

if( 
    
strtotime($date) >= strtotime($date1) && 
    
strtotime($date) <= strtotime($date2
){
    
//...
} else {
    
//...


You are exactly right, in the top when defining the date it is the string and when we compare any string resultant will be true always. In only case if it is integer or date in right format then we can compare.
.NET and CodeIgniter Software Engineer 
Reply


Messages In This Thread
RE: Comparison Operators >= in Control Structures why false? - by MrJunaidShahid - 04-10-2019, 01:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB