DateAdd issue

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Good day all:
I am having an issue in my windows application with the date add function.
<br/>
I am in the United States and the windows application is for users in the Ukraine. This application needs to be run in the United States and in the Ukraine.
The following are code fragments:
DisplayMonth = 10 (October)<br/>
DisplayYear = 2012<br/>
Countrycode = "uk-UA"
Dim DK as string = (DispayMonth.ToString + "/01/" + DisplayYear.ToString).ToString<br/>
At this point DK = "10/01/2012" - correct date format "mm/dd/yyyy" for en-US<br/>
Dim FirstDate as Date = Date.Parse(DK, New CultureInfo(Utility.CounrtyCode, True))<br/>
At this point FirstDate = "01/10/2012" - this is what I want, date formatted "dd/mm/yyyy" for Ukraine
dim PreviousMonth as Integer = dateadd(DateInterval.Month, -1,FirstDate)<br/>
PreviouseMonth = 12 - Wrong <br/>
I am expecting PreviousMonth = 9
FYI: <br/>
Globalization.CultureInfo.CurrentCultrue.Name = "uk" <br/>
Globalization.CultureInfo.CurrentCulture.EnglishName = "Ukrainian"<br/>
(This is what I expect)
So the problem is DateAdd. From the documentation I have found I believe the Date "functions" should be tied to the globalization current cultur setting, so I dont understand why it appears to be subtracting one from the day not the month.
<br/>
<br/>
Any assistance on how to correct this would be appreciated!
Robert


View the full article
 
Back
Top