Reputation: 1841
My site is set to en-GB in the web.config. I have a calendar extended textbox control on a page which lets the user select date, in GB format as string (DD/MM/YYYY). I need to convert this to a US datetime before inserting into db.
solution: (MM/dd/yyyy hh:mm:ss)
I do hate mondays. Overthinking as usual.
Upvotes: 1
Views: 500
Reputation: 269298
If @bookingdate
is already a DateTime
parameter then leave it alone. The database doesn't care about the string representation of the date - the underlying date/time is the same regardless of how you decide to format it when you call ToString
.
(ie, Just comment-out the entire chunk of code shown in the question and see if that works.)
Regarding your most recent edit and comments, I suspect that you simply need to do something like this:
Dim dt As DateTime = DateTime.ParseExact(InputBookingdatesingleday.Text,
"dd/MM/yyyy",
CultureInfo.GetCultureInfo("en-GB"))
command.Parameters.AddWithValue("@bookingdate", dt)
Upvotes: 2