DateTime FormatException error

senzacionale picture senzacionale · Sep 8, 2011 · Viewed 8.3k times · Source
DateTime datuMDokumenta = Convert.ToDateTime(txtDatumDokum.Text);

txtDatumDokum.Text is like "09.09.2011".

but i get FormatException error. Must i parse date?

Answer

gyurisc picture gyurisc · Sep 8, 2011

Try DateTime.ParseExact with the dd.MM.yyyy format string

 DateTime.ParseExact(txtDatumDokum.Text, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);