Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using CONVERT() function
Message
From
07/02/2019 19:18:52
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
01666022
Message ID:
01666081
Views:
34
>>>>>>>I found the solution. Instead of using .ToShortDateString() on the ASP.NET side, I have to use a specific format:
>>>>>>>
>>>>>>>
>>>>>>>TargetDate.Date.ToString("yyyy-MM-dd HH:mm:ss");
>>>>>>>
>>>>>>>
>>>>>>>The above works for both the American date and the British Date.
>>>>>>
>>>>>>This is the format I have been saying since the beginning :) So you had access to the code, good.
>>>>>
>>>>>Yes, I wrote all the bad code :) I just didn't know how to set the string to the correct format. As I said, it was working for years with the .ToShortDateString() (here in is the USA). The customer in Europe exposed the "hole" in my code and I had to change it.
>>>>>Thank you for bringing it up to my attention.
>>>>
>>>>BTW since you are not really using time:
>>>>
>>>>
TargetDate.Date.ToString("yyyyMMdd");
>>>>
>>>>Note: No dash or other separator in between. Otherwise it fails under some versions with specific language settings (like TURKISH).
>>>
>>>You maybe right. But in my SQL Server SP code I am converting this string to a DateTime type (code I wrote in another message). So, I am concerned that if I don't add the time portion (which is not used), the value of the variable will be set correctly. So far, in my testing, the string with dashes and the time work.
>>>But if it starts causing problems, I will change it.
>>
>>OK I repeat, don't add separators. Time part is up to you. I wouldn't wait for it to cause troubles when there is a safe version exists.
>
>When I remove the separators (that is, using "yyyyMMdd"), I get error again. When I have separators, no error.
>I think it all comes back to how I use this field in the SQL server SP.

Removing separators you get error just because you are forcing the result to be char(10), right?
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform