Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ashwinr87

macrumors member
Original poster
Mar 9, 2011
81
0
Hi,

say for example I have the following piece of code with which I retrieve the date from the database

Code:
 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
Code:
@property (nonatomic, retain) NSDate * startDate;

iii)CommonHelper is another file where I have the getDateString: function as below,
Code:
+ (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...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.