cancel
Showing results for 
Search instead for 
Did you mean: 

Filter a 'List of Files Names' Collection by a Date ( Filter Date)

SaurabhPalkar
Level 3
ToDate([All File List.Last Written]) >= [Filter Date], does not yield logical results. How do you use date in comparisons ? ( See details attahed)
4 REPLIES 4

david.l.morris
Level 14
If you're referring to the action 'Filter Collection' in the Collection Manipulation object, you have to give it a field to work with, which means you won't be able to dynamically convert to a Date like that. However, I would think the filter would still work even when comparing a Date (Filter Date) to a Date Time (Last Written). Try this in the expression field for the filter input of the Filter Collection action. (Notice that [Last Written] is a literal string referring to the name of the field in the collection): ""[Last Written] >= "" & [Filter Date]
Dave Morris 3Ci at Southern Company Atlanta, GA

SaurabhPalkar
Level 3
Hi David, Thank you so much. I get an error: ""Internal: Could not execute code stage because exception thrown by code stage: Cannot perform '>=' operation on System.DateTime and System.Double."" So I interpret that it kind progressed some. BUT the Filter Date variable I have created as a Date type appears to show as a Double ?    

david.l.morris
Level 14
Try putting single quotes around the Filter Date that gets resolved. Maybe like this: ""[Last Written] >= ' "" & [Filter Date] & "" '
Dave Morris 3Ci at Southern Company Atlanta, GA

AmiBarrett
Level 12

I've got another variant of this that lets you pass a raw SQL query against the DataTable. If you treat it like any other SQL table, it should give you the result you need. Pretty sure the CAST() and CONVERT() statements are supported, if you need to change the datatypes. The query would look something like ""Select * where [Last Written] >= CONVERT(datetime, ""&[Filter Date]&"")""

Inputs:
Collection - Collection
Query - Text

Outputs:
Sorted Collection - Collection

DataTable temp = Collection.Clone(); 
DataRow[] dr = Collection.Select(Query); 
foreach(DataRow row in dr) {
     temp.ImportRow(row); 
} 
Sorted_Collection = temp;