Reputation: 8071
How to store current date and time in Sqlite using PhoneGap?
tx.executeSql("CREATE TABLE IF NOT EXISTS myorder(orderid INTEGER PRIMARY KEY AUTOINCREMENT,cdatetime VARCHAR)");
tx.executeSql('INSERT INTO myorder(orderid,cdatetime) VALUES(NULL,"01/01/2012 01:00:00")',[],successOrderfunction,errorfunction);
Is it correct way to store?
Upvotes: 0
Views: 4603
Reputation: 13567
Try:
tx.executeSql('CREATE TABLE IF NOT EXISTS expens (Etype TEXT,amount REAL,created_at DATETIME DEFAULT CURRENT_TIMESTAMP)');
Upvotes: 0
Reputation: 12523
You can save the current datetime as long. Define your table column with the long-datatype and insert your value like this:
tx.executeSql("CREATE TABLE IF NOT EXISTS myorder(orderid INTEGER PRIMARY KEY, cdatetime long)");
tx.executeSql("INSERT INTO myorder(cdatetime) VALUES("+myDate.getTime()+")",[],successOrderfunction,errorfunction);
By the way. There is no need to use autoincrement. If you try to insert a null value in a primary key integer the field is automatically converted into an integer which is one greater than the largest value of that column.
Upvotes: 3
Reputation: 367
I don't use sqlite or phonegap but you cannot add null in your pk table. Add a number or don't add anything at all.
tx.executeSql('INSERT INTO myorder(cdatetime) VALUES("01/01/2012 01:00:00")',[],successOrderfunction,errorfunction);
This should work, you created an incremental pk.
tx.executeSql('INSERT INTO myorder(orderid,cdatetime) VALUES(1, "01/01/2012 01:00:00")',[],successOrderfunction,errorfunction);
This should also work, I think in sqlite you can add pk manually.
Upvotes: 1