0

I have a calendar control:
<asp:Calendar ID="cldDepartDate" runat="server"></asp:Calendar>

And for example, if I chose 14th of March 2019, using the code below to display:
lblTest.Text = cldDepartDate.SelectedDate.ToString()

I got "3/14/2019 12:00:00 AM"

And now I want to convert it to "14/3/2019 12:00:00 AM" and store it into a Date object.

So far I have tried:

Dim oDate As Date = Date.ParseExact(cldDepartDate.SelectedDate.ToString("dd/MM/yyyy"), "MM/dd/yyyy", CultureInfo.InvariantCulture)

But it gives me this error:
enter image description here

Henry
  • 631
  • 10
  • 21
  • See this [link](https://stackoverflow.com/questions/19296433/convert-datetime-in-c-sharp-to-yyyy-mm-dd-format-and-store-it-to-mysql-datetime) this can help you to achieve what you are looking at... – Abhinaw Kaushik Mar 08 '19 at 11:06

1 Answers1

1
    Dim dateString = "3/14/2019 12:00:00 AM"
    Dim oDate As Date = Date.ParseExact(dateString, "M/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture)
    Debug.Print(oDate.ToString("dd/M/yyyy hh:mm:ss tt"))

Using the standard DateTime formats.

https://learn.microsoft.com/en-us/dotnet/api/system.globalization.datetimeformatinfo?view=netframework-4.7.2#Formatting_dates_times

Mary
  • 14,926
  • 3
  • 18
  • 27