I have a DataTable according to the Client Requirement it can contain invalid date
say “00/00/1999”,NULL,Empty String.(Typed DatSet)
When i collect them as enumerables i wish to convert any of those invalid forms to empty string.
(i.e)
EnumerableRowCollection<DataRow> query =
from order in _table.AsEnumerable()
select
new {
OrderDate=
string.IsNullorEmpty(Convert.ToString(order.Field<DateTime>("OrderDate"))
||
(How to check Date is Invalid date)
? String.Empty : order.Field<DateTime>("OrderDate")
}
How to check whether a Date is a valid Date or not?
DateTime.TryParse…like this given your current code:
(using notepad for an IDE so apologies if there’s a syntax error but that should give you the general idea)
I’m assuming that OrderDate is a string since you are trying to assign it string.Empty, if its a DateTime then change the ternary assignment to something like DateTime.MinValue in place of the empty string (or whatever you want to use for your “invalid” dates, since an empty string is no longer an option) :
or if OrderDate is a nullable DateTime then