Friday, 30 March 2012

How to compare two dates and How to Know Sunday on the particular date


function todaydate()
    {
    debugger;
        var Todaydate =new Date() ;

        var TextBoxDate=document.getElementById("TxtDate").value;
        var currentDate = new Date()
        var day = currentDate.getDate()
        var month = currentDate.getMonth() + 1
        var year = currentDate.getFullYear()
       
        if (TextBoxDate.length < 10)
        {
         alert('Please Enter Correct Date!');
         return false;
        }
       
        if (month < 10)
            {
                Todaydate= ("0" + month + "/" + day + "/" +  year) ;
            }
        else
            {
                Todaydate= (month + "/" + day + "/" +  year) ;
            }       
        var ConvertTodayDate= Date.parse (Todaydate);       
        var date1 = new Date(ConvertTodayDate)    
    
        var day1 = TextBoxDate.substring(0,2);
        var month1 = TextBoxDate.substring(4,5);
        var year1 = TextBoxDate.substring(6,10);
    
      if (month1 < 10)
            {
                TextBoxDate= ("0" + month1 + "/" + day1 + "/" +  year1) ;
            }
        else
            {
                TextBoxDate= (month1 + "/" + day1 + "/" +  year1) ;
            }
           
       var  ConvertTextBoxDate= Date.parse (TextBoxDate);
       var date2 = new Date(ConvertTextBoxDate)



      if (date2  < date1)
        {
        alert("Order cannot be booked for same day and back day !");
            return false
        }
     
       if (Todaydate == TextBoxDate)
         {
            alert("Order cannot be booked for same day and back day !");
            return false
         }

        //Given Below Line for Getting Sunday

        var forsunday = date2.getDay(); 
        if (forsunday == 0)
         {
        alert("Order cannot be booked for Sunday!");
        return false
         } 
        
         if(document.form1.DDlDelTime.selectedIndex==0)
         {
         alert('Please Select Delivery Time. !')
        
         return false;
         }
        
      var IISHours = document.getElementById("LblHours").innerHTML;
      var Min = document.getElementById("LblMin").innerHTML;
      var IISDate = document.getElementById("LblDate").innerHTML;
      TextBoxDate=document.getElementById("TxtDate").value;



        if (IISDate == TextBoxDate)
        {
                if (IISHours > 22 && Min > 0)
                {
                alert('Order cannot be booked for Tomorrow after 10 PM.');
                return false;
                }
        }  

}

No comments:

Post a Comment