Js code that determines whether a date can be queried across months

  • 2020-03-30 03:35:37
  • OfStack

function checkDate(startDate, endDate, num, flag) { 
     
    if(startDate == null || endDate == null) { 
      popwin.info(' prompt ',' The date cannot be empty '); 
      return false;   
    } 
 
    if(startDate == '' || endDate == '') { 
      popwin.info(' prompt ',' Please enter the query date '); 
      return false;   
    } 
     
    var start_date = startDate + " 00:00"; 
    var end_date = endDate + " 00:00"; 
    start_date = new Date(start_date.replace(/-/g, "/")); 
    end_date = new Date(end_date.replace(/-/g, "/")); 
    if(start_date > end_date){ 
      popwin.info(' prompt ',' The deadline must not be less than the start date '); 
      return false;   
    } 
     
    //Gets the date after num day
    var currentDate = new Date(); 
    currentDate.setDate(currentDate.getDate() + num); 
     
    if(end_date > currentDate) { 
      popwin.info(' prompt ',' The deadline cannot be greater than ' + num + ' The date after the day '); 
      return false;  
    } 
     
    //Determine whether to cross - month query
    if(flag == false) { 
      if(start_date.getMonth() != end_date.getMonth()) { 
        popwin.info(' prompt ',' This query does not support cross-month queries '); 
        return false;  
      } 
    } 
  } 

Related articles: