how to check valid date in c#

Jak
Jak
Member
858 Points
132 Posts

Hi,

how to check valid date in c#? Is there any inbuilt function for that?

Views: 34775
Total Answered: 2
Total Marked As Answer: 1
Posted On: 13-Dec-2015 07:05

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
Teacher
4822 Points
23 Posts
         

Hi Jak,

In C#, there is no inbuilt method to check date. But you can create you own method to check valid date as: 

public static bool IsDate(string tempDate)
DateTime fromDateValue; 
var formats = new[] { "dd/MM/yyyy", "yyyy-MM-dd" }; 
if (DateTime.TryParseExact(tempDate, formats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out fromDateValue))
return true;
else
return false;
}
}

 

Cal above method as :

IsDate("01/12/2015");
Posted On: 14-Dec-2015 07:34
Priya
Priya
Participant
936 Points
28 Posts
         

Hi,

It's work for me.

Posted On: 21-Dec-2015 23:37
 Log In to Chat