Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 842551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:58:53+00:00 2026-05-15T05:58:53+00:00

I have an Sqlite database in which I want to select rows of which

  • 0

I have an Sqlite database in which I want to select rows of which the value in a TIMESTAMP column is before a certain date. I would think this to be simple but I can’t get it done. I have tried this:

SELECT * FROM logged_event WHERE logged_event.CREATED_AT < '2010-05-28 16:20:55'

and various variations on it, like with the date functions. I’ve read http://sqlite.org/lang_datefunc.html and http://www.sqlite.org/datatypes.html and I would expect that the column would be a numeric type, and that the comparison would be done on the unix timestamp value. Apparantly not. Anyone who can help? If it matters, I’m trying this out in Sqlite Expert Personal.

Edit:

Here’s type table description:

CREATE TABLE [logged_event]
(
[id] INTEGER  NOT NULL PRIMARY KEY,
[created_at] TIMESTAMP,
[name] VARCHAR(64),
[data] VARCHAR(512)
);

And the test data:

INSERT INTO table VALUES(1,'2010-05-28T15:36:56+0200','test','test');
INSERT INTO table VALUES(2,'2010-05-28T16:20:49+0200','test','test');
INSERT INTO table VALUES(3,'2010-05-28T16:20:51+0200','test','test');
INSERT INTO table VALUES(4,'2010-05-28T16:20:52+0200','test','test');
INSERT INTO table VALUES(5,'2010-05-28T16:20:53+0200','test','test');
INSERT INTO table VALUES(6,'2010-05-28T16:20:55+0200','test','test');
INSERT INTO table VALUES(7,'2010-05-28T16:20:57+0200','test','test');
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:58:54+00:00Added an answer on May 15, 2026 at 5:58 am

    The issue is with the way you’ve inserted data into your table: the +0200 syntax doesn’t match any of SQLite’s time formats:

    1. YYYY-MM-DD
    2. YYYY-MM-DD HH:MM
    3. YYYY-MM-DD HH:MM:SS
    4. YYYY-MM-DD HH:MM:SS.SSS
    5. YYYY-MM-DDTHH:MM
    6. YYYY-MM-DDTHH:MM:SS
    7. YYYY-MM-DDTHH:MM:SS.SSS
    8. HH:MM
    9. HH:MM:SS
    10. HH:MM:SS.SSS
    11. now
    12. DDDDDDDDDD

    Changing it to use the SS.SSS format works correctly:

    sqlite> CREATE TABLE Foo (created_at TIMESTAMP);
    sqlite> INSERT INTO Foo VALUES('2010-05-28T15:36:56+0200');
    sqlite> SELECT * FROM Foo WHERE foo.created_at < '2010-05-28 16:20:55';
    sqlite> SELECT * FROM Foo WHERE DATETIME(foo.created_at) < '2010-05-28 16:20:55';
    sqlite> INSERT INTO Foo VALUES('2010-05-28T15:36:56.200');
    sqlite> SELECT * FROM Foo WHERE DATETIME(foo.created_at) < '2010-05-28 16:20:55';
    2010-05-28T15:36:56.200
    

    If you absolutely can’t change the format when it is inserted, you might have to fall back to doing something “clever” and modifying the actual string (i.e. to replace the + with a ., etc.).


    (original answer)

    You haven’t described what kind of data is contained in your CREATED_AT column. If it indeed a datetime, it will compare correctly against a string:

    sqlite> SELECT DATETIME('now');
    2010-05-28 16:33:10
    sqlite> SELECT DATETIME('now') < '2011-01-01 00:00:00';
    1
    

    If it is stored as a unix timestamp, you need to call DATETIME function with the second argument as 'unixepoch' to compare against a string:

    sqlite> SELECT DATETIME(0, 'unixepoch');
    1970-01-01 00:00:00
    sqlite> SELECT DATETIME(0, 'unixepoch') < '2010-01-01 00:00:00';
    1
    sqlite> SELECT DATETIME(0, 'unixepoch') == DATETIME('1970-01-01 00:00:00');
    1
    

    If neither of those solve your problem (and even if they do!) you should always post some data so that other people can reproduce your problem. You should even feel free to come up with a subset of your original data that still reproduces the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text field in SQLite database, which I want the user to
I have a sqlite (v3) table with this column definition: timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
I have an SQLite database in the first version of my iPhone application (which
I have a SQLite database with cyrillic rows in it. For example: CREATE TABLE
I have one sqlite database in which I store both user-defined information and information
I have an sqlite database full of huge number of URLs and it's taking
I am using the SQLite database and have the following persistent class (simplified): public
I use Netbeans IDE (6.5) and I have a SQLite 2.x database. I installed
I have a database file that is generated on a PC using Sqlite. This
I have a SQLite database that contains a huge set of log messages. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.