How can i parse the below datetime as exact?
DateTime dt = DateTime.Parse(row.Cells[2].Value.ToString());
when the above code is executed i get error: 'String was not recognized as a valid DateTime.'
the format of the date in that column is as follows: dd/MM/yyyy mm:HH:ss

3 answers
It's probably because you're using a 'foreach' loop but making changes to the collection each time a Row is deleted which changes the indexing of the remaining rows. In effect, the next row after the one deleted will be skipped even though it may need deleting itself.
When you're doing multiple deletions, the safest thing to do is to use an ordinary 'for' loop but iterate through the collection backwards so that deletions don't affect the indexing of the remaining elements.
I'd therefore try it like this:
answered one year ago by:
17279
690
Thank you very much, i have applied that format and it works great. and thanks for the advice.
I'd try:
Incidentally, are you sure that the minutes precede the hours which is an unusual format?
answered one year ago by:
17279
Ooops yes you was right vulpes, typo there ;-)
Your code does build fine with no errors, i'm using it as below, my plan is to remove the row that contains a date older than todays date, the below kind of works but still shows some older dates, can you see what i'm doing wrong?
answered one year ago by:
690