0

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?

2
  • this specifies SQLite's datetime format. Can you put some debug into your code to print out exactly the string that's getting sent to SQLite? Commented May 12, 2012 at 1:27
  • Like I said, I'm using a Javascript date object, so the format is: Fri May 11 2012 20:32:54 GMT-0600 (MDT) Commented May 12, 2012 at 2:33

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Ah yes, that was the issue. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.