sOnt
sOnt

Reputation: 97

SQLite select records from last 24 hour

I have this struct of data stored in an SQLite DB:

stored datas

I'm trying to get the records from the past 24 hours in a php code.

I use the following query that I found at similar questions:

SELECT temp FROM Sysstat 
WHERE when >= date('now', '-1 days') AND when < date('now')

But it doesn't seem to work and gives error:

Warning: SQLite3::prepare(): Unable to prepare statement: 1, near "when": syntax error in..

Anyone could give me some advice?

Upvotes: 4

Views: 3337

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175964

Enquote when with " or [] or backticks:

SELECT temp 
FROM Sysstat 
WHERE "when" >= date('now', '-1 days') AND "when" < date('now');

SQLite Keywords:

The list of keywords is so long that few people can remember them all. For most SQL code, your safest bet is to never use any English language word as the name of a user-defined object.

If you want to use a keyword as a name, you need to quote it.

"keyword" A keyword in double-quotes is an identifier.

  1. WHEN

Upvotes: 6

Related Questions