Click here to Skip to main content
15,914,406 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code and i have a query that an error is coming "System.Convert doesnot contain defination for Isdate". How to remove this error.

C#
public bool page_IsValid()
   {
       bool result = true;

       if ((!Convert.IsDate(Request["start_date"])) | (!Convert.IsDate(Request["end_date"])))
       {
           result = false;
       }
       else
       {
           if (Convert.ToDateTime(Request["start_date"]) > Convert.ToDateTime(Request["end_date"]))
               result = false;
       }
       return result;
   }
Posted
Updated 10-Jun-15 23:32pm
v2

Use DateTime.TryParse[^] instead.
 
Share this answer
 
Comments
Member 11758222 11-Jun-15 5:56am    
where i should use this? I have used this instead of IsDate. But still it is not accepting
CHill60 11-Jun-15 6:13am    
See DamithSL's amended solution
there is no Convert.IsDate, try as below
C#
public bool page_IsValid()
{
   DateTime start;
   DateTime end;
   return DateTime.TryParse(Request["start_date"], out start) && DateTime.TryParse(Request["end_date"], out end)
         && end>=start;
}
 
Share this answer
 
v2
Comments
Member 11758222 11-Jun-15 6:01am    
How to use it?
DamithSL 11-Jun-15 6:03am    
check my updated 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