views:

32

answers:

1

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.

+2  A: 

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)
LukeH
I agree - he just wants `command.Parameters("@bookingdate").Value = gbDT` - but that doesn't explain his parse error unfortunately. [Actually he's just added an 'I've also tried' this]
Rup
I have tried simplifying and have edited the question with the code
Phil
@Rup: He doesn't even need that: `gbDT` is parsed from `@bookingdate` in the first place. The entire chunk of code is superfluous.
LukeH
D'oh, yes, I read the first parse as reading it from the form and populating the query with that. So Phil where do you get the data from the form and what type is that in? And how did the @bookingdate already get set? By data binding from a control? How's that control set up?
Rup
@Phil: What exact value(s) of `InputBookingdatesingleday.Text` are causing that error?
LukeH
@LukeH it is a date string like DD/MM/YYYY (29/10/2010).
Phil
@Rup here is the code: command.Parameters.Add("@bookingdate", Data.SqlDbType.DateTime) command.Parameters("@bookingdate").Value = Convert.ToDateTime(InputBookingDate.Text)
Phil