Neelesh
Neelesh

Reputation: 3693

insert dates to SQLite

I am planning to have an 'remind me on date' feature on my application. Hence I would want to receive the date from the user and store in SQLite.

What is the easiest way to do this? Should i use the UIDatePicker? If so, can you give me an hint of how to do it?

Is it simpler to use 3 picker views for year, month and date and store in SQLite?

Sorry if my question is a bit vague. I am new to iPhone development. I will be very thankful if someone can help me with this.

Upvotes: 2

Views: 2217

Answers (2)

Ishu
Ishu

Reputation: 12787

save date in string format.

Pick date from datePicker and conver into string and save it in db when you need this date you can again convert it into NSDate object.

see this

NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"MM/dd/YYYY"];
    NSString *dateString= [NSString stringWithFormat:@"%@",
                           [df stringFromDate:self.datePicker.date]];

save dateString in database.

Upvotes: 3

Anomie
Anomie

Reputation: 94794

For getting the date from the user, certainly use UIDatePicker.

For saving it, first consider using Core Data instead of sqlite directly. But if you insist, the easiest would probably be to convert the NSDate to a double using timeIntervalSinceReferenceDate for storage, and use [NSDate dateWithTimeIntervalSinceReferenceDate:...] to get back the NSDate when loading from the database.

Upvotes: 2

Related Questions