Below sample code can be used to convert a string in to DateTime in MM/dd/yyyy format.
DateTime dateValue;
if (DateTime.TryParseExact(txtPassword.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValue))
{
DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
dtfi.ShortDatePattern = "MM/dd/yyyy";
dtfi.DateSeparator = "/";
DateTime convertedDate= Convert.ToDateTime(txtPassword.Text, dtfi);
}
DateTime dateValue;
if (DateTime.TryParseExact(txtPassword.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValue))
{
DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
dtfi.ShortDatePattern = "MM/dd/yyyy";
dtfi.DateSeparator = "/";
DateTime convertedDate= Convert.ToDateTime(txtPassword.Text, dtfi);
}
thanks
ReplyDelete