strange date-time format

  • Thread starter Thread starter Pawel Janik
  • Start date Start date
P

Pawel Janik

Hello...

I have the following problem. I have date in ddMMyyHHmmss format.
Is there some Parse(String format) method, because i cannot find goot
parameters for DateTime.Parse(....)?
 
Pawel Janik said:
I have the following problem. I have date in ddMMyyHHmmss format.
Is there some Parse(String format) method, because i cannot find goot
parameters for DateTime.Parse(....)?

I prefer ParseExact to Parse for this kind of thing - you need
something like:

DateTime x = DateTime.ParseExact
(value, "ddMMyyyy", CultureInfo.InvariantCulture.DateTimeFormat);

Note that which CultureInfo you wish to use will depend on exactly
where you're getting the data from. (Admittedly with the patterns we're
talking about it's unlikely to make much difference as far as I can
see, but with other patterns it would.)
 
Jon said:
I prefer ParseExact to Parse for this kind of thing - you need
something like:

DateTime x = DateTime.ParseExact
(value, "ddMMyyyy", CultureInfo.InvariantCulture.DateTimeFormat);

Note that which CultureInfo you wish to use will depend on exactly
where you're getting the data from. (Admittedly with the patterns
we're talking about it's unlikely to make much difference as far as I
can see, but with other patterns it would.)

Thanks a lot. It works perfectly!

Pawel Janik
 
Back
Top