DateTime

  • Thread starter Thread starter Viorel Ghilas
  • Start date Start date
V

Viorel Ghilas

Hi all

I have some trouble. I hava configurable date format, for ex. like this
'yyyyMMdd' and I try to convert strings to date time, and .net give me an
error 'string is not recognized as a valid DateTime', my code is:

DateTimeFormatInfo df = new DateTimeFormatInfo();
df.DateSeparator = string.Empty;
df.FullDateTimePattern = mask;
DateTime d = DateTime.Parse("20041012", df);

how to solve this problem

with best regard
Viorel Ghilas
 
Viorel Ghilas said:
I have some trouble. I hava configurable date format, for ex. like this
'yyyyMMdd' and I try to convert strings to date time, and .net give me an
error 'string is not recognized as a valid DateTime', my code is:

DateTimeFormatInfo df = new DateTimeFormatInfo();
df.DateSeparator = string.Empty;
df.FullDateTimePattern = mask;
DateTime d = DateTime.Parse("20041012", df);

Use DateTime.ParseExact, and provide the date format as one of the
parameters.
 
Back
Top