I would alter the datatable and use a DateTime datatype for the date column. This allows for direct comparison with Now.AddDays(-14).
A good practice is to keep data formats as close to reality as possible. Using integersā¦? store them as integer. Same with dates.
And the least you should do is compare apples to apples. Converting a date to an integer (using cInt ), and then checking if it is smaller or larger than a string value will yieldā¦ unexpected results.
Only cast values to strings when you need to actually transform them to text, like log messages, or tying into etc.
Converting from any type into a string is usually a lot easier and clearer than the other way around.
Unfortunately, I have no control over the initial table.
The date is stored in the initial table in the format yyyyMMdd as a string.
First it must be converted to the format date and then filtering must take place. It doesnāt matter if the conversion and the filtering happen in one step or not.
How can I convert a whole column, without the header row, from String to Date?
I have tried that, unfortunately without success.
(From row In varDtInitial.Select()
Where CDate(row("POSTEING_QUEST"))>Now
Select row).CopyToDataTable
Multiple Assign: Can not assign ā(From row In varDtInitial.AsEnumerable
Where CDate(row(āPOSTEING_ANFRAGEā).toString.Trim).Date>Now.AddDays(-14).Date
Select row).CopyToDataTableā to āvarDtGefiltertā.
you can do the following for handling the 00000000 rows like
(From d In varDtInitial.AsEnumerable
Let chk1 = DateTime.TryParseExact(d("POSTEING_QUEST").toString.Trim,"yyyyMMdd", CultureInfo.InvariantCulture,DateTimeStyles.None, Nothing)
Let chk2 = If(chk1, DateTime.ParseExact(d("POSTEING_QUEST").toString.Trim,"yyyyMMdd", CultureInfo.InvariantCulture).Date > Now.AddDays(-14), True)
Where chk2
Select r = d).CopyToDataTable
it will keep the rows with nonparseable dates and rows with the date greater than minus 14 days back
ensure following:
just incorporate also the empty result pattern optional, when needed
BTW: if SQL is used for retrieving the data, then working as close as pssible on the source is a preferred option. Check also to do the filtering directly within the SQL statement