say for example I have the following piece of code with which I retrieve the date from the database
DateLabel.text = [CommonHelper getDateString:objSample.startDate :@"MM/dd/yyyy"];
where
i) objSample is an object of my Sample entity
ii) startDate is an attribute in the Sample entity declared as @property (nonatomic, retain) NSDate * startDate;
iii)CommonHelper is another file where I have the getDateString: function as below,
+ (NSString *) getDateString: (NSDate *) date: (NSString *) format
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:format];
NSString *dateStr = [dateFormat stringFromDate:date];
[dateFormat release];
return dateStr;
}
Using Sqlite Database Browser, if I enter the value as “04/23/1999” to the Sample’s startDate attribute , the value which is displayed in DateLabel.text is a totally different value and if I enter a value such as “76851234”, the value which is displayed in DateLabel.text is “05/23/2001”.
Since I am new in dealing with database, I am unable to understand why this happens…
Would someone be able to tell me why this happens? and is there a way I can directly enter the date into the database using SQLite Database Browser so that that date is displayed?
is the format of the date I enter into the SQLite database browser a “Unix Date Format”? if so, how would I be able to convert the date into unix date format so that I know for certain what would be the exact date I would be displaying on my app…
The answer for this is that you can’t.
SQLite is “typeless“. This means that you can store any kind of data you want in any column of any table, regardless of the declared datatype of that column. http://www.sqlite.org/datatypes.html