Ramco Ramco

Ramco Ramco

  • 441
  • 3.4k
  • 520.7k

String was not recognized as a valid DateTime

Sep 19 2022 6:14 AM

Hi

<asp:DropDownList ID="ddlDates" class="form-control" DataTextFormatString="{0:dd/MM/yyyy}" required="true" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Date_SelectedIndexChanged">
                                    </asp:DropDownList>

DateTime? dtFrom = null;

            DateTime PMDate2 = DateTime.ParseExact(ddlDates.SelectedItem.Value, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
            dtFrom = Convert.ToDateTime(PMDate2.ToString("yyyy-MM-dd"));

Thanks


Answers (1)