date validation not to be today

后端 未结 3 550
無奈伤痛
無奈伤痛 2021-01-27 16:01

I need to validate 2 date that never should be same.If same it will return false.Code is in PHP.It is always giving o/p as false.

function BeforeAdd($values, $me         


        
相关标签:
3条回答
  • 2021-01-27 16:27

    U can use fucntion strtotime and compare it

     $d1 = "1/2/2015";
     $d2= "1/2/2016";
    
        if ( strtotime($d1) == strtotime($d2) )
           echo "same";
         else
           echo "different";
    

    copy this code and test it i resolve your problem this is my last edit

    <?php
    $d1 = "1/2/2015";
    $d2= "1/2/2015";
    
    
    
    
    
        if ( strtotime($d1) != strtotime($d2) ) {
            return true;  
        }
        else
        {
    
        echo '<script type="text/javascript">';
        echo 'alert("Application date and leave date should be different.")';
        echo '</script>';
    
        return false;
        }
    
    ?>
    
    0 讨论(0)
  • 2021-01-27 16:34
    function BeforeAdd($values, $message='', $inline='', $pageObject='') {
    
        $d1 =$values['DATE'];     //date 1 in dd/mm/yyyy format
        $d2 =$values['DATE_OF_LEAVE'];   //date 2 in dd/mm/yyyy format
    
        if($d1 <> $d2) {
            return true;  
        }
    
        echo '<script type="text/javascript">';
        echo 'alert("Application date and leave date should be different.")';
        echo '</script>';
    
        return false; 
    
    
    }
    

    You need to change $values['DATE OF LEAVE'] to $values['DATE_OF_LEAVE']. Also in the example you have some fields you don't use - I made them optional and changed the javascript code a little.

    0 讨论(0)
  • 2021-01-27 16:50

    Any one can suggest me a code to return false id date is today else true in the format

    function BeforeAdd($values, $message, $inline, $pageObject)
    {
        $d1 = $values['DATE'];     //date 1 in dd/mm/yyyy format
        $d2 = now();  
    
        if($d1>$d2)
        {
            return true;  
        }
    
        echo '<script language="javascript">';
        echo 'alert(Application date and leave date should be different.)';
        echo '</script>';
    
        return false;  
    }
    
    0 讨论(0)
提交回复
热议问题