Reading Date from database in Ipad

Discussion in 'iOS Programming' started by ashwinr87, Apr 25, 2011.

  1. macrumors member

    Joined:
    Mar 9, 2011
    #1
    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...
     

Share This Page