Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date/Time condition #72

Open
Thaybow opened this issue Jan 17, 2020 · 1 comment
Open

Date/Time condition #72

Thaybow opened this issue Jan 17, 2020 · 1 comment

Comments

@Thaybow
Copy link

Thaybow commented Jan 17, 2020

Hello,

Does someone can tell me what am I doing wrong ?

DB is installed. The field 'completed' in table is a TEXT (and I have also tried with a DATE).

Trying to do this:

async delete() { const db = await this.getInstance(); await db.transaction((tx) => { const sql = 'DELETE FROM my_table WHERE (completed < DATE(\'now\', \'-1 minute\'))'; tx.executeSql(sql, [], (tx, res) => { console.log('removed'); }, function(tx, error) { console.log('DELETE error: ' + error.message); }); }); }

I can delete everything without the WHERE condition, but I'm stuck when I try to filter with this WHERE (completed < DATE('now', '-1 minute'))

@brodycj
Copy link

brodycj commented Jan 17, 2020

Thanks. I had trouble following your sample code, reformatting here:

async delete() {
        const db = await this.getInstance();
        await db.transaction((tx) => {
            const sql =
                'DELETE FROM my_table WHERE (completed < DATE(\'now\', \'-1 minute\'))';
            tx.executeSql(sql, [], (tx, res) => {
                console.log('removed');
            }, function(tx, error) {
                console.log('DELETE error: ' + error.message);
            });
        });
    }

I generally recommend formatting JavaScript samples like this:

```js
// some code here
```

(or use ts, jsx, or tsx in case of TypeScript, jsx, or tsx code)

Unfortunately I cannot think of very much without knowing how you populated the completed field in the first place.

Back in 2016 I started to document some pitfalls I discovered related to time and date handling in the following places:

and some important reading here: https://www.sqlite.org/lang_datefunc.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants