Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys

Would like to know if anyone would be able to assist.

About a week or 2 ago,something changed on my production server not sure if there were changes made from the networking team or if windows updates that were released that could have caused the issues but for some reason my application now reads a CDate as 02018/01/02 instead of 2018/01/02.

I have ran the code on my dev machine, and have deployed and tested the service on the QA/ and pre-prod environments and they all work fine, its only on the production server that i am having this issue.

What I have tried:

I have checked the regional settings and they dont seem to have changed.
Debugged/ and tested on other servers and the service runs fine with no issues
Posted
Updated 3-Jan-18 1:27am
Comments
Maciej Los 2-Jan-18 2:43am    
Does the date value is stored as a date or as a string? Can you post exact value stored on server?

There's nothing wrong with using CDate function, but i'd recommend to use newer technics to convert string to date/time value, because of several reasons. More you'll find here: Type Conversion Functions (Visual Basic) | Microsoft Docs[^]

Please, check this: Parsing Date and Time Strings in the .NET Framework | Microsoft Docs[^]
So, DateTime.Parse or DateTime.ParseExact is that what you're looking for.

In general: you have to use date instead of string data type to avoid several problems in a future. Note, that different CultureInfo[^], which may cause the date (stored in a string) to be not convertible.
 
Share this answer
 
v2
You can use String.Format("{0:yyyy/MM/dd}", DateObject)
 
Share this answer
 
Found the issue, the service was running under a different user account, when logged in found the year had 5 y in regional settings
 
Share this answer
 
Comments
Maciej Los 3-Jan-18 7:38am    
As i mentioned in my answer, you'll never get such of troubles, when you'd use date data type instead of string.
Cheers,
Maciej
;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900