Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Thanks!

like image 702
Dave Avatar asked Oct 14 '22 07:10

Dave


2 Answers

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.

like image 141
Barry Wark Avatar answered Oct 19 '22 03:10

Barry Wark


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.

Pseudocode:

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.

like image 21
TechZen Avatar answered Oct 19 '22 03:10

TechZen