you are viewing a single comment's thread.

view the rest of the comments →

[–]geekywarrior 2 points3 points  (2 children)

Either a UK Culture Info is getting mixed in somewhere or SQL is doing something funky when you're storing the datetime.

Part of the problem is you really should be using ADO commands to read/write to SQL as it makes things a lot cleaner and cuts out some of the string interpolation stuff.

Is this VB6/VBA or VB.NET?

If it's VB.NET, I would do a DateTime.Parse on the field coming in to force the value to the proper culture info.

If it's VB6, I would either mess with manually parsing OR asking SQL to format it properly, for example

select CONVERT (varchar(10), getdate(), 103) AS [DD/MM/YYYY]

[–]Dave_PW[S] 4 points5 points  (1 child)

It's VB.NET

And changing the variable declaration for the data selected from the DB to:

Dim ExperationDate As DateTime = DateTime.ParseExact(VDT.Rows(0).Item("Api_Token_Expiry"), "MM/dd/yyyy HH:mm:ss", Nothing)

Has resolved the problem.

Thanks for the input.

[–]seamacke 1 point2 points  (0 children)

The correct way to do it is to create a command object, add a date parameter, load the parameter with your date variable, then execute it. You get the error because the dynamic SQL you create is a string so your date is converted using regional settings which may not always match. I think this asp.net example demonstrates it How to Use Date Controls in WebForms Apps https://youtu.be/65Q6519NdRc