Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Datetime problem
Message
From
21/06/2017 15:48:38
 
General information
Forum:
C#
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01652147
Message ID:
01652149
Views:
47
>This line of code is failing for one client
>
>parameter.Value = Convert.ToDateTime(parameterValue);
>
>but works fine for me.
>
>The value is "06/21/2017 11:30:56".
>
>I suspect (and it's very likely) that this client's locale is Spanish, so the date would not be properly recognized.
>
>The question is - how should I adjust the code above? I assume that the date will always come in US locale, but I can not guarantee this 100% for sure. I also can not demand that the calling application will send the date in ISO format.
>
>So, what is the best solution here?

It appears you know, from that value, what is the month, the day and the year, for example. However, when using generic functions, they might depend on local settings. Thus, you might end up in difficult situations such as the one expressed. I never rely on functions like that. There has to be a way of knowing the format used. As this is the case here, I would usually rely on a full conversion such as the following where you could adjust accordingly to the parts for what is the day, the month and the year, assuming cValue is the date in a string format:
Dim lcDateTime As String = ""
Dim ldDate As Date = Nothing
Dim lnDay As Integer = 0
Dim lnHour As Integer = 0
Dim lnMinute As Integer = 0
Dim lnMonth As Integer = 0
Dim lnSecond As Integer = 0
Dim lnYear As Integer = 0

' Initialization
lcDateTime = Trim(cValue)
lnYear = Val(Mid(lcDateTime, 1, 4))
lnMonth = Val(Mid(lcDateTime, 6, 2))
lnDay = Val(Mid(lcDateTime, 9, 2))
lnHour = Val(Mid(lcDateTime, 12, 2))
lnMinute = Val(Mid(lcDateTime, 15, 2))
lnSecond = Val(Mid(lcDateTime, 18, 2))

ldDate = New Date(lnYear, lnMonth, lnDay, lnHour, lnMinute, lnSecond)
Basically, this approach is then usable as is from one development environment to another.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform