1

I have a simple table in my database:

CREATE TABLE [InformacjeZDziekanatu] (
  [_id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
  [DataWstawienia] DATE NOT NULL, 
  [DataModyfikacji] DATE NOT NULL, 
  [Tresc] VARCHAR2 NOT NULL);

In my application only what I want to do is to get value of DataWstawienia column. I am using such method:

try {
    ResultSet result = stat.executeQuery("select * from InformacjeZDziekanatu order by _id desc limit 5");
    int id;
    Date dataWst;
    Date dataMod;
    String tresc;               

    for(int j = 0 ; j < 5 ; j++) {
            result.next();
            Object[] lista = new Object[4];
            id = result.getInt("_id");
            dataWst = result.getDate("DataWstawienia");
            dataMod = result.getDate("DataModyfikacji");
            tresc = result.getString("Tresc");
            lista[0] = id;
            lista[1] = dataWst;
            lista[2] = dataMod;
            lista[3] = tresc;
            dane[j] = lista;

    }
}

All dates in DataWstawienia column are today's dates but using this method above I get 1970-01-01 date all the time.

What did I do wrong?

harpun
  • 4,022
  • 1
  • 36
  • 40
k4sia
  • 414
  • 1
  • 6
  • 18
  • How do you save the dates? 1970 means it is interpreted as 0. – zapl Oct 06 '13 at 16:35
  • 1
    I've got it! Problem was in lines: dataWst=result.getDate("DataWstawienia"); dataMod = result.getDate("DataModyfikacji"); Instead of this i should use : result.getString("DataWstawienia"); and change type of dataWst to a String. Now everything works correctly. – k4sia Oct 06 '13 at 16:37
  • the same problem: http://stackoverflow.com/questions/9829362/sqlite-current-timestamp-always-1970-01-01 – k4sia Oct 06 '13 at 16:39

1 Answers1

1

SQLIte does not have a DATE data type. Dates need to either be stored as integers (number of seconds since Unix Epoch is common) or as ISO 8601 times (e.g. 2013-10-01T12:12:12). If you say DATE in your SQLite schema you will store values as strings. Your solution of changing the type of dateWst to String acknowledges the fact that you are storing dates as strings and not as an internal date type.

vy32
  • 28,461
  • 37
  • 122
  • 246