javascript思路:
1.你有三种时间表示,利用indexOf("-"或者"年")(伪码)确定下日期格式
2.分离年月日,利用split()
3.进行逻辑判断
具体的函数用法你可以到msdn里面查,vbScript也大同小异,至于asp呵呵,它不就可以用js或者vbs来做吗?

解决方案 »

  1.   

    这是我以前写的一个判断日期的例子:)很乱,也很烦嗦,不过可以用,你看看
    function OK()
    {
       
      
      
         var thedate = 2003-08-08;
      
      var the_date = thedate.split('-');
      var theyear = parseInt(the_date[0]);
      var themonth = parseInt(the_date[1]);
      
      var thedate2 = 2004-08-08;
      var the_date2 = thedate2.split('-');
      var theyear1 = parseInt(the_date2[0]);
      var them = the_date2[1].indexOf("0");

      var themonth1 = "";
      if(them == 0)
      {
         themonth1=parseInt(the_date2[1].substring(1));
      }  
      else
      {
         themonth1 = parseInt(the_date2[1]);
      }     
                 
      if(thedate == "")
      {
        alert("请输入起始时间!");
        return;
      }
      else
      {
        if(thedate2 == "")
        {
          alert("请输入结束时间!")
          return;
        }
        else
        {
          if(document.form1.startdate.value > document.form1.enddate.value)
          {
            alert("结束时间不能早于起始时间,请重新输入时间!");
            return;
          }
          else
          {  
            switch(theValue)
            {
              case "byDate":
                 if((theyear1-theyear) != 0)
                 {
                     if((theyear1-theyear) == 1 && themonth1 > themonth)
                    {
                      alert('对不起,按日分析只能分析一年以内的数据,请重新输入数据!');
                      return;
                    }  
                    if((theyear1-theyear) > 1)
                    {
                      alert('对不起,按日分析只能分析一年以内的数据,请重新输入数据!');
                      return;
                    }   
                 }
                 alert("OK");
                 break;
              case "byWeek":
                 if((theyear1-theyear) != 0)
                 {
                     if((theyear1-theyear) == 1 && themonth1 > themonth)
                    {
                      alert('对不起,按周分析只能分析一年以内的数据,请重新输入数据!');
                      return;
                    }  
                    if((theyear1-theyear) > 1)
                    {
                      alert('对不起,按周分析只能分析一年以内的数据,请重新输入数据!');
                      return;
                    }   
                 }
                 alert('ok');
                 break;
               case "byMonth":
                 if((theyear1-theyear) > 1)
                 {
                     if((theyear1-theyear) == 2 && themonth1 > themonth)
                    {
                      alert('对不起,按月分析只能分析二年以内的数据,请重新输入数据!');
                      return;
                    }  
                    if((theyear1-theyear) > 2)
                    {
                      alert('对不起,按月分析只能分析二年以内的数据,请重新输入数据!');
                      return;
                    }   
                 }
                 alert('ok');
                 break;
               case "bySeasion":
                 if((theyear1-theyear) > 2)
                 {
                     if((theyear1-theyear) == 3 && themonth1 > themonth)
                    {
                      alert('对不起,按季度分析只能分析三年以内的数据,请重新输入数据!');
                      return;
                    }  
                    if((theyear1-theyear) > 3)
                    {
                      alert('对不起,按季度分析只能分析三年以内的数据,请重新输入数据!');
                      return;
                    }   
                 }
                 alert('ok');
                 break;
              case "byYear":
                 if((theyear1-theyear) > 2)
                 {
                     if((theyear1-theyear) == 3 && themonth1 > themonth)
                    {
                      alert('对不起,按季度分析只能分析三年以内的数据,请重新输入数据!');
                      return;
                    }  
                    if((theyear1-theyear) > 3)
                    {
                      alert('对不起,按季度分析只能分析三年以内的数据,请重新输入数据!');
                      return;
                    }   
                 }
                 alert('ok');
                 break;         }
          
          }
        }
      }
      
    }
      

  2.   

    <%
    'asp
    function bj1(date1,date2)
    date1=replace(date1,"年","-")
    date1=replace(date1,"月","-")
    date2=replace(date2,"年","-")
    date2=replace(date2,"月","-")
    date1=replace(date1,"日","")
    date2=replace(date2,"日","")
    '如果是  2003年4月2日这种格式时,变成 2003-04-02格式
    date1=cdate(date1)
    date2=cdate(date2)
    return date2-date1
    '返回差多少天,>180......时就是半年了。
    end function
    function bj2(date1,date2)
    date1=mid(date1,2,0)&"-"&mid(date1,2,2)&"-"&mid(date1,2,4)
    date2=mid(date2,2,0)&"-"&mid(date2,2,2)&"-"&mid(date2,2,4)
    '总知就是把它转换成 xxxx-xx-xx格式了
    bj1(date1,date2)
    end function
    %>
    如果是2003-03-04或2003年03月03日这种格式时就使用bj1否则使用bj2

    if bj("2003-06-01","2002-12-30")>182 then
             response.write("大于半年")
    else
              '没有
    end if
    建议在vbs角本中使用,因为可以自动计算日期型变量的差。