Reputation: 641
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)
Upvotes: 0
Views: 1584
Reputation: 15091
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.
Upvotes: 1