Simple String To Date Time

S

skeet

Cor said:
To do it culture independent without months, than this is for me the way.

Dim myDate As DateTime = DateTime.ParseExact("11 05 2001", "dd MM yyyy",
Nothing)

DateTime mijDate = DateTime.ParseExact("11 05 2005", "dd MM yyyy", null);

It tells exact that as culture nothing is used, which will not work as I
wrote before if the month is written in a culture dependent way (in words).

Yes it will - because if you pass in null/Nothing, that means "use the
current culture". (Read the docs and try it for confirmation of this.)
In other words, you're asking for a culturally sensitive parse -
implying to the reader of the code that you care which the current
culture is.
CultureInvariant means in fact nothing else than Culture 'en-*'. The
culture of all countries where English is spoken as first language.

No, it means the invariant culture. Even if it comes out as an English
culture, the meaning you should read when someone has written
CultureInfo.InvariantCulture is "I don't want this operation to be
culture-sensitive".

Jon
 
C

Cor Ligthert [MVP]

Jon,
No, it means the invariant culture. Even if it comes out as an English
culture, the meaning you should read when someone has written
CultureInfo.InvariantCulture is "I don't want this operation to be
culture-sensitive".
This is your own explanation not accoording to the documentation about this
and absolutly not accoording to the working from it as I tested it.

It does work with the English invariant culture (en-*) however absolute not
with the Dutch culture when MMM or MMMM is used.

Did you try that already?

Cor
 
S

skeet

Cor said:
This is your own explanation not accoording to the documentation about this
and absolutly not accoording to the working from it as I tested it.

On the contrary, it's exactly what the documentation says. From MSDN on
CultureInfo.InvariantCulture:

<quote>
If a security decision depends on a string comparison or a case-change
operation, use the InvariantCulture to ensure that the behavior will be
consistent regardless of the culture settings of the system. However,
the invariant culture must be used only by processes that require
culture-independent results, such as system services; otherwise, it
produces results that might be linguistically incorrect or culturally
inappropriate.
It does work with the English invariant culture (en-*) however absolute not
with the Dutch culture when MMM or MMMM is used.

Did you try that already?

<sigh> I don't know how many different ways I can say this...

When you use "MMM" or "MMMM" that is by its very nature a
culture-sensitive pattern - it uses names, which vary by culture.
Specifying the InvariantCulture would be a mistake in that situation,
certainly - as indicate by the quoted docs. I've never suggested that
though. I've suggested that you should use InvariantCulture when you
want to perform a parse which is culturally invariant - when you want
to make it clear to whoever's reading the code that you don't care what
culture the current thread is running in - the results should be the
same whatever the culture is.

Jon
 
C

Cor Ligthert [MVP]

Jon,

As I said so often, don't misquote when you are in a discussion with me, it
makes you at least for me unbelievable and than your messages have less
value for me, what they normally don't do..See below of your text.
On the contrary, it's exactly what the documentation says. From MSDN on
CultureInfo.InvariantCulture:

<quote>
If a security decision depends on a string comparison or a case-change
operation, use the InvariantCulture to ensure that the behavior will be
consistent regardless of the culture settings of the system. However,
the invariant culture must be used only by processes that require
culture-independent results, such as system services; otherwise, it
produces results that might be linguistically incorrect or culturally
inappropriate.
</quote>

This is what is written about it. The rest as this is above is a kind of
explanation in the text that cannot be seen apart from this first row in the
explanation.

The CultureInfo.InvariantCulture property is neither a neutral nor a
specific culture. It is a third type of culture that is culture-insensitive.
It is associated with the English language but not with a country or region.

That says direct all I am telling in this message thread it is a 'en-*'
culture.

It is in both descriptions the main part.

http://msdn.microsoft.com/library/d...e/html/cpconusinginvariantcultureproperty.asp

http://msdn.microsoft.com/library/d...tioncultureinfoclassinvariantculturetopic.asp


Cor
 
S

skeet

Cor said:
As I said so often, don't misquote when you are in a discussion with me, it
makes you at least for me unbelievable and than your messages have less
value for me, what they normally don't do..See below of your text.

Could you say *exactly* what I misquoted? I included every part of the
message I was replying to, so I don't see how I could have misquoted
that. I didn't include *all* the documentation on
CultureInfo.InvariantCulture, but then you didn't include *all* the
documentation in your quote either.

Yes, you have *said* "so often" that I've misquoted. You've very rarely
actually shown it to be the case though.
This is what is written about it. The rest as this is above is a kind of
explanation in the text that cannot be seen apart from this first row in the
explanation.

Eh? I was referring to the direct documentation for
CultureInfo.InvariantCulture - the documentation that referred to in
the second link. Are you suggesting we should ignore every part of all
pages of documentation other than the first sentence in each page?
The CultureInfo.InvariantCulture property is neither a neutral nor a
specific culture. It is a third type of culture that is culture-insensitive.
It is associated with the English language but not with a country or region.

That says direct all I am telling in this message thread it is a 'en-*'
culture.

No, it says more than that. It says it's culture-insensitive, just as
you've quoted above.

You wrote a few messages ago:

<quote>
CultureInvariant means in fact nothing else than Culture 'en-*'.
</quote>

If it meant "nothing else" than that, why would the documentation
bother saying that actually it's culture-insensitive? The primary
description for CultureInfo.InvariantCulture isn't "Gets the en-*
culture" it's "Gets the CultureInfo that is culture-independent
(invariant)." The main concern of the invariant culture isn't its
language - it's its culture independence, as I've said repeatedly.

As it's culture-independent, you should not use it with a format which
is culture-dependent. However, when you use a format which is
culture-independent, I believe it's a good idea to specify
CultureInfo.InvariantCulture to make that culture-independence clear.

The format which was given at the start of this thread was
culture-independent so I believe it's entirely reasonable to specify
CultureInfo.InvariantCulture, and this correctly indicates the nature
of the format in a way that specifying Nothing/null doesn't (as then
the current culture is used).

Jon
 
C

Cor Ligthert [MVP]

Jon,
No, it says more than that. It says it's culture-insensitive, just as
you've quoted above.

Beg your pardon, what did I quote?
\\\\
The CultureInfo.InvariantCulture property is neither a *neutral* nor a
*specific* culture.
////

However, I see your problem, you are not aware that there are cultures were
English is not the first language.

Cor
 
J

Jon Skeet [C# MVP]

Cor said:
Beg your pardon, what did I quote?
\\\\
The CultureInfo.InvariantCulture property is neither a *neutral* nor a
*specific* culture.
////

Yes, you quoted that. Maybe I misunderstood this sentence: "That says
direct all I am telling in this message thread it is a 'en-*' culture."

Could you try rewriting it?

I've never disputed that CultureInfo.InvariantCulture uses English as
its language. The question is whether it's designed to be used as an
InvariantCulture, used for culture-independent parsing etc.
However, I see your problem, you are not aware that there are cultures were
English is not the first language.

You seem to still be missing the point. Let's see if we can work out
where:
1) Do you believe that the format the OP gave is culture-sensitive?
2) Do you believe that culture-insensitive formats should be parsed
using a particular culture?

My answers to 1 and 2 are "No" and "No", which is why I suggested (and
still suggest) using CultureInfo.InvariantCulture on the OP's format.

Now, could you explain why you think it's worth specifying a particular
culture for a culture-insensitive format?

Jon
 
C

Cor Ligthert [MVP]

Jon,
Yes, you quoted that. Maybe I misunderstood this sentence: "That says
direct all I am telling in this message thread it is a 'en-*' culture."

Could you try rewriting it?
Why, I thought that there is not much more to tell, beside that you maybe
did not understand that I did mean with * any culture inside that 'en'
language area however it seems for me obvious for everybody who knows a
little bit of computing that the * is a wildchart character..
I've never disputed that CultureInfo.InvariantCulture uses English as
its language. The question is whether it's designed to be used as an
InvariantCulture, used for culture-independent parsing etc.
You did and even do in now. It is culture dependent, because it is not as
written a *neutral* culture..
You seem to still be missing the point. Let's see if we can work out
where:
1) Do you believe that the format the OP gave is culture-sensitive?
2) Do you believe that culture-insensitive formats should be parsed
using a particular culture?

We do not discuss the question of the OP, that was already done, we are
discussing this serious question from me to you, where this subthread
started with. At that time I had not investigate it. For a special reason I
had last week to investigate it, and now my knowledge divers from what you
answered me, and therefore I have informed you about that.

With this started the question.
\\\
Why are you using so consequently the Culture.InvariantCulture, are you sure
that it outside the English language area does not give problems?
///

Cor
 
J

Jon Skeet [C# MVP]

Cor Ligthert said:
Why, I thought that there is not much more to tell, beside that you maybe
did not understand that I did mean with * any culture inside that 'en'
language area however it seems for me obvious for everybody who knows a
little bit of computing that the * is a wildchart character..

Yes, I understood that part. But there's more to the invariant culture
than "it's en-*", contrary to an earlier post made by you. It's a
culture-insensitive culture, as documented in MSDN (in documentation
you yourself have quoted). If it were as simple as being associated
with the English language but no specific country/region, it would just
be a neutral English culture. However, it's not a neutral culture, as
we both agree.
You did and even do in now. It is culture dependent, because it is not as
written a *neutral* culture..

But nor is it a specific culture. It is culture-insensitive, as you
quoted in the docs. (Even neutral cultures are culture-dependent - a
neutral French culture would have a different DateTimeFormat to a
neutral English culture, for example.)
We do not discuss the question of the OP, that was already done

Oh - that's news to me. As far as I was aware, you were questioning my
original answer to the OP.
we are
discussing this serious question from me to you, where this subthread
started with. At that time I had not investigate it. For a special reason I
had last week to investigate it, and now my knowledge divers from what you
answered me, and therefore I have informed you about that.

With this started the question.
\\\
Why are you using so consequently the Culture.InvariantCulture, are you sure
that it outside the English language area does not give problems?
///

And I thought I'd answered that question several times. The format
being used is not culture-sensitive, so a culture-insensitive
CultureInfo is a good idea IMO.

I note that you didn't answer the questions I asked in the previous
post. Is that because you agree with my answers on them?
 
C

Cor Ligthert [MVP]

Jon,
I note that you didn't answer the questions I asked in the previous
post. Is that because you agree with my answers on them?
As I would not have agreed in that part of the OP, than I would have said it
much earlier.

I have opened this thread as a question to you related to the question of
the OP. While busy with something your answer did not work in the situation
MMMM MMM.

Beside that, is it in my opinion better to use the nothing for telling that
there nothing used as special culture than a faked culture that reached it
the best in non MMM and MMMM situations.

Maybe is it that "nothing" tells explicitly more than "null", although I
have no problem with that as well. However if you disagree that part, than
it is in my idea just a matter of opinion and not so important for the
result, in those situations the culture (third parameter in ParseExact) is
not used at all.

Cor
 
J

Jon Skeet [C# MVP]

Cor Ligthert said:
As I would not have agreed in that part of the OP, than I would have said it
much earlier.

I have opened this thread as a question to you related to the question of
the OP. While busy with something your answer did not work in the situation
MMMM MMM.

Indeed. Quite often I give answers which wouldn't work in different
situations - I address the situation provided instead.
Beside that, is it in my opinion better to use the nothing for telling that
there nothing used as special culture than a faked culture that reached it
the best in non MMM and MMMM situations.

But Nothing *doesn't* say that - it says (as I've said twice already)
to use the current culture. It's exactly as if you wrote

DateTime.ParseExact (..., ..., Thread.CurrentThread.CurrentCulture);
Maybe is it that "nothing" tells explicitly more than "null", although I
have no problem with that as well.

No, as a reference type is involved I'm happy to see them as
equivalent.
However if you disagree that part, than
it is in my idea just a matter of opinion and not so important for the
result, in those situations the culture (third parameter in ParseExact) is
not used at all.

But specifying the invariant culture makes that clearer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top