I had a Windows application that was processing files and as part of that was converting strings into dates.
In the Windows app - the entry of 'Nov-08' was being converted to a date with:
- day = 1
- month = 11
- year = 2008
However within a Windows service (using the same code as the Windows application) I get the same entry of 'Nov-08' being converted into a date with:
- day = 8
- month 11
- year = 2009
On further investigation I'm finding the 'System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern' value differs between the Windows application and the Windows service.
The Windows application has this set as 'dd/MM/yyyy' - whereas the Windows service has this set as 'M/d/yyyy'.
Which then explains the string conversions to sates that I am seeing.
How can I read an entry of 'Nov-08' through the Windows service in the same way as through the Windows application (version).
The entry format 'Nov-08' is not fixed - but the string should be read using the 'dd/MM/yyyy' date format.
How can this be done?
I've tried changing the value of System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern - but this is found to be read only.
Any help / pointers would be appreciated.
Thanks in advance.
Steve
In the Windows app - the entry of 'Nov-08' was being converted to a date with:
- day = 1
- month = 11
- year = 2008
However within a Windows service (using the same code as the Windows application) I get the same entry of 'Nov-08' being converted into a date with:
- day = 8
- month 11
- year = 2009
On further investigation I'm finding the 'System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern' value differs between the Windows application and the Windows service.
The Windows application has this set as 'dd/MM/yyyy' - whereas the Windows service has this set as 'M/d/yyyy'.
Which then explains the string conversions to sates that I am seeing.
How can I read an entry of 'Nov-08' through the Windows service in the same way as through the Windows application (version).
The entry format 'Nov-08' is not fixed - but the string should be read using the 'dd/MM/yyyy' date format.
How can this be done?
I've tried changing the value of System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern - but this is found to be read only.
Any help / pointers would be appreciated.
Thanks in advance.
Steve