parse dates

  • Thread starter Thread starter memememe
  • Start date Start date
M

memememe

I need to be able to parse both of these dates with the same method, and
return them as a DateTime object. Is there any methods that would do this
blindly or do I need to provide the format?

Feb 25 23:11

Dec 1 2002
 
Hi,

You might try DateTime.Parse using InvariantCulture:

DateTime dt = DateTime.Parse(yourdate,
System.Globalization.CultureInfo.InvariantCulture)

Miha
 
thanks for the idea, but it didnt work :-(
im actually starting to think that it might be a good idea to try catch it
with one format using parseexact and if it fails, I try the other format, of
course that only works if those are the two only possible formats, which I
am not sure they are.
 
It never changes (it is not regional setting dependent) - it is fixed and
you are certain what you'll get.

Miha
 
It never changes (it is not regional setting dependent) - it is fixed and
you are certain what you'll get.
I know this. I was just not my understanding that he wanted something
regional setting independent.
I think he was just trying to solve his problem in English, without thinking
what happens if in 2 months the marketing guys will ask for German.
I need to be able to parse both of these dates with the same method, and
return them as a DateTime object. Is there any methods that would do this
blindly or do I need to provide the format?

My normal answer would be: use DateTime.Parse.
And depending on what you need, you may use a CultureInfo or not,
invariant or not.

Mihai
 
It never changes (it is not regional setting dependent) - it is fixed and
you are certain what you'll get.
I know this. I was just not my understanding that he wanted something
regional setting independent.
I think he was just trying to solve his problem in English, without thinking
what happens if in 2 months the marketing guys will ask for German.
I need to be able to parse both of these dates with the same method, and
return them as a DateTime object. Is there any methods that would do this
blindly or do I need to provide the format?

My normal answer would be: use DateTime.Parse.
And depending on what you need, you may use a CultureInfo or not,
invariant or not.

Mihai
 
Mihai N. said:
I know this. I was just not my understanding that he wanted something
regional setting independent.
I think he was just trying to solve his problem in English, without thinking
what happens if in 2 months the marketing guys will ask for German.


My normal answer would be: use DateTime.Parse.
And depending on what you need, you may use a CultureInfo or not,
invariant or not.

Mihai

I actually solved the problem we had by first calling parse, if that failed,
I would call parseExact and I would give it a formats array tht contained
what we consider valid formats so far. The reason I didnt do just the
parseExact call is because there is a lot of possible date formats we might
get that might not be on our formats array but maybe the parse method would
understand.
 
Back
Top