0
votes

I have an NSDate attribute called startDate stored in the persistence store in string format like "2020-01-01T23:59:26+0530". I am trying to fetch all the data from the core data which falls before this date. But in my predicate I am not understanding how to form a format string. If the startDate was in Date format, then it would be something like below, let predicate = NSPredicate(format: "date < %@", startDate) But my "date" is not Date instead its a string. I'm not sure how to convert the stored date in string format to just Date format only and apply that in Predicates for comparison. Any suggestions?

1
"I have an NSDate attribute called startDate stored in the persistence store in string format" Do you mean to say date rather than startDate here. startDate is a Date object right? - Sweeper
startDate is a string. Example, say current date is 2020-01-01T23:59:26+0530 then my startDate will be "2020-01-01T23:59:26+0530" - S.P

1 Answers

1
votes

If you need the time information as well when storing, then it is better to store it as a Date in CoreData because it is very hard and unnecessary coding to compare these.

If you only need date information, then when storing it to CoreData save it with only Date and compare it like this Comparing date string with NSPredicate