Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite select records from last 24 hour

Tags:

php

sqlite

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?

like image 476
sOnt Avatar asked Sep 12 '25 22:09

sOnt


1 Answers

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
like image 107
Lukasz Szozda Avatar answered Sep 14 '25 20:09

Lukasz Szozda