how to check valid date in c#

Jak
Jak
Member
352 Points
151 Posts

Hi,

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

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

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
Moderator
1170 Points
210 Posts
Marked as answer      

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
Member
62 Points
26 Posts
     

Hi,

It's work for me.

Posted On: 21-Dec-2015 23:37
banner

Blog

Active User (2)

 Log In to Chat