SQLite strftime() support with Core Data FetchRequest

My entity has a startDate (NSTime) attribute where I use the date and time in my detail display of the entity.

And in my list, I need to group my entities by day (YYMMDD) based on the start date; and I want to ensure that it can adapt to the region where the user is currently (e.g. if user travels or migrate, the YYMMDD should be adapted based on the current region). Does Core Data SectionedFetchRequest supports strftime() functions from SQLite (https://sqlite.org/lang_datefunc.html) or what is an effective alternative sectioned fetch in my case?

Answered by DTS Engineer in 856412022

I don't think you can use strftime() directly with Core Data – Core Data supports NSExpressionDescription, hence supports some predefined functions listed here, and strftime() is not there.

You can achieve your goal by using transient attribute though. How to do that is demonstrated in this sample code.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I don't think you can use strftime() directly with Core Data – Core Data supports NSExpressionDescription, hence supports some predefined functions listed here, and strftime() is not there.

You can achieve your goal by using transient attribute though. How to do that is demonstrated in this sample code.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

SQLite strftime() support with Core Data FetchRequest
 
 
Q