Tutorial :Best way to store date/time into core data


For each course I am storing the day of the week the class the user has...and the start and end time and room no. What would be the best approach in terms of data type, Like for storing time?? so that when I pull it out I can display it e.g 1:00 PM.



Use a date attribute in your managed object model for each time you want to store. See the section on "Dates and Times" in the Core Data Programming Guide.


If its an actual date e.g. Tuesday, December 15th 2010 1:00pm CST, then you can use a data attribute.

However, if it's just a generic time of day e.g. any given Wednesday at 1:00pm, the you will need to create attributes to hold the day, the time and meridian as strings and or numbers.

I would recommend creating a entity in the model just for this information and then setting a relationship to it.


DayAndTimeEntity{      weekdayName = sting;      timeOfDay = string or number; //use a number if you need to do calculations      isAM = BOOL;  }  

in use, "any Monday at 1:00pm" would look like:

aDayAndTimeEntityInstance{      weekdayName = "Monday";      timeOfDay = "1:00"       isAM = NO;  }  

Then set a relationship to any other entities that need to store this time. You can elaborate on the basic idea as needed.


Date Type should work

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »