Click here to Skip to main content
15,911,789 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Dear All,

Please take a look at the following javascript:

C#
function validate()
    {
            if(!checkDate( document.form1.txtFdate.value ) )
            {
                alert("Invalid Date");
                document.getElementById("txtFdate").focus();
                return false;
            }
            if(!checkDate( document.form1.txtTdate.value ) )
            {
                alert("Invalid Date");
                document.getElementById("txtTdate").focus();
                return false;
            }
            var dateString=document.form1.txtFdate.value;
            var Fdate = (dateString.substring(6,10))+(dateString.substring(3,5))+(dateString.substring(0,2));
            dateString=document.form1.txtTdate.value;
            var Tdate = (dateString.substring(6,10))+(dateString.substring(3,5))+(dateString.substring(0,2));
            if(parseInt(Tdate,10)<parseInt(Fdate,10))
            {
                alert("To Date Cannot Be Less Than From Date");
                document.getElementById("txtTdate").focus();
                return false;
            }
            if((parseInt(Tdate,10)-parseInt(Fdate,10))>6)
            {
                alert("Difference Between From and To Date Cannot Be More than 6 Days");
                document.getElementById("txtTdate").focus();
                return false;
            }

           }



Here Its working fine for the Individual month, but if I select 31st march to 1st April, it gives the same message saying "Difference Between From and To Date Cannot Be More than 6 Days".
What might be the problem in this? please help me.....
Posted
Updated 8-Mar-11 23:16pm
v2

try :

var Fdate = (dateString.substring(7,10))+(dateString.substring(3,4))+(dateString.substring(0,1));

the same for Tdate ...
 
Share this answer
 
Comments
Raj.rcr 9-Mar-11 8:07am    
Noooo.. Its not working.. I tried this..!
The precise method for date comparison would be convert the date to milliseconds/ seconds (timestamp) before comparing. It is an alternative suggestion
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900