Armin,
As Dragon suggests:
| My fault. I passed 'Nothing' as the 3rd argument. Passing InvariantInfo
| works.
If you pass Nothing for the 3rd argument it means to use
CultureInfo.CurrentCulture.
Which may have its DateTimeFormatInfo set to expect something other the /
for the date separator (in the case of Europe & Russia verses the US).
I normally use CultureInfo.InvariantInfo (which has an invariant
DateTimeFormatInfo object attached) instead of
DateTimeFormatInfo.InvariantInfo. In either case
DateTimeFormatInfo.InvariantInfo says to expect / for the date separator.
The "/" in "dd/M/yyyy" says to use the date separator from the
DateTimeFormatInfo object passed, while the "\/" in "d\/M\/yyyy" says to use
a "/" literally as the date separator.
See DateTimeFormatInfo.DateSeparator:
http://msdn.microsoft.com/library/d...DateTimeFormatInfoClassDateSeparatorTopic.asp
And Custom DateTime Format Strings:
http://msdn.microsoft.com/library/d...ide/html/cpconcustomdatetimeformatstrings.asp
For details.
Hope this helps
Jay
| > Armin,
| > | First I wanted to suggest ParseExact too, but it doesn't work if
| > it's | "24/12/2005", thus the self-written function.
| >
| > Really! which version of the framework?
| >
| > Dim ChristmasEve As DateTime =
| > DateTime.ParseExact("24/12/2005", "dd/M/yyyy",
| > Globalization.DateTimeFormatInfo.InvariantInfo)
| > Debug.WriteLine(ChristmasEve.ToLongDateString())
| >
| >
| > Returns: Saturday, December 24, 2005 on .NET 1.1 (in the US, in
| > other countries it will Return Dec 24th 2005 in possibly other
| > formats)!
|
|
| My fault. I passed 'Nothing' as the 3rd argument. Passing InvariantInfo
| works.
|
| I don't understand why this makes the difference. Maybe the formats are
| different, i.e. the order of month, day, year or the seperator is
different,
| but why does one allow a single digit only while the other one accepts one
| or two digits? I thought (Parse)exact means (Parse)exact.
|
|
| But wait... this also works:
|
| d = DateTime.ParseExact("24/10/2005", "d\/M\/yyyy", Nothing)
| d = DateTime.ParseExact("4/10/2005", "d\/M\/yyyy", Nothing)
| d = DateTime.ParseExact("24/1/2005", "d\/M\/yyyy", Nothing)
| d = DateTime.ParseExact("4/1/2005", "d\/M\/yyyy", Nothing)
|
| Same format string independent from number of digits per day or month.
|
|
| Armin
|