I have a datepicker control for the users to pick the date, however, they also need to enter the date manually. As such, I need to validate the date entered by the user in the textbox.
Below is the code that I am using to validate
DateTime Test;
if ((!string.IsNullOrEmpty(strtdate)))
{
bool valid = DateTime.TryParseExact(strtdate, "MM/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out Test);
}
The date entered by the user is 6/29/2011, however it gives the bool valid value as false though it is correct.
What am I missing here? Please let me know, its urgent.
Thanks.
use the following format “M/dd/yyyy”
M is for 1..12