Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Datetime problem
Message
 
 
To
21/06/2017 15:48:38
General information
Forum:
C#
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01652147
Message ID:
01652150
Views:
43
For now I just added the cultureinfo into the Convert function. I think with the 99.999% probability the date either will come in ISO format or us-locale.

However, I'm not 100% sure. I was thinking perhaps I may need to figure out what format is used with the RegEx, but that may be an overkill.

At least for now I would assume that the coming date string is either ISO or us-locale.


>>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.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform