Miles
Miles

Reputation: 1635

Storing Javascript Date in SQLite with ExtJS

I'm writing an application in ExtJS that uses WebSQL to store data in a SQLite database in the browser. (The requirements are for only web-kit browsers, lucky me right?) I'm running into a problem with date fields.

I'm using ExtJS's datefields in my UI which handles Javascript dates. My SQLite schema uses datetime fields to store them. SQLite complains about a contraint violation when I save data, but the data still gets there so I don't really care.

The problem is that I need to do some date comparing in SQLite in order to populate an ExtJS grid. But because the date format is in the Javascript data format and not one of SQLite's acceptable datetime formats, doing my comparison in the sql doesn't work.

My sql can't compare the dates because it's not in the format that SQLite expects. How do I fix that?

I've tried using the Ext.Data.format() when saving the data to put it in a format that SQLite likes ("Y-m-d") but to no avail. I've also looked into converting from the Javascript Date format to the SQLite datetime format in my sql with the Date() function, but that hasn't worked either.

Any ideas?

Upvotes: 0

Views: 938

Answers (1)

Wilk
Wilk

Reputation: 8113

It doesn't work neither with this?

Ext.create ('Ext.container.Container', {
    renderTo: Ext.getBody () ,
    items: [{
        xtype: 'datefield' ,
        fieldLabel: 'date' ,
        format: "Y-m-d"
    } , {
        xtype: 'button' ,
        text: 'Push me' ,
        listeners: {
            click: function (button) {
                console.log (button.previousSibling('datefield').getRawValue());
            }
        }
    }]
});

It prints '2012-05-12'. If you used getValue() you were wrong because (from the ExtJS Doc):

Returns the current data value of the field. The type of value returned is particular to the type of the particular field (e.g. a Date object for Ext.form.field.Date), as the result of calling rawToValue on the field's processed String value. To return the raw String value, see getRawValue.

Hope this help you :D

Ciao

Upvotes: 1

Related Questions