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 6880359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:57:50+00:00 2026-05-27T04:57:50+00:00

I am working with SQLite and Python and try to get these specific dates

  • 0

I am working with SQLite and Python and try to get these specific dates (and corresponding values). I think an example explainst best what I am looking for.
Consider selecting from this data:

-(2011-01-02, 4.0)
-(2011-01-14, 5.0)
-(2011-02-02, 5.5)
-(2011-02-07, 6.5)
-(2011-02-12, 7.0)
-(2011-02-15, 4.0)
-(2011-03-02, 2.5)
-(2011-03-09, 3.5)

with a period-distance of one month (or a multiple) between the first date and all the dates we are looking for we return this data:

-(2011-01-02, 4.0)
-(2011-02-02, 5.5)
-(2011-03-02, 2.5)

I was looking for an SQL-statement which provides me with this data, if that is possible.

Additional question:
if there is no date-point which is exactly a multiple of a month away from the initial date, how can I get the nearest date in my database?

I hope that my explanation is clear enough. If not, thanks for telling.

  • 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-27T04:57:51+00:00Added an answer on May 27, 2026 at 4:57 am

    It sounds like this won’t be a flexible enough solution for your needs, but to answer your question directly, here is a query that gets you what you need.

    Also, since you didn’t specify table/column names, my test table I used is called foo, and has columns created and value.

    select
        foo.created, foo.value
    from 
        -- Subquery to pick first record to base rest of query on
        (
            select
                created,
                strftime('%d', created) as day
            from
                foo
            order by
                created
            limit 1
        ) as bar
    
        -- Join all rows in foo that are greater than that found in 'bar'
        -- and has the same day of the month.
        join foo
            on foo.created >= bar.created
               and strftime('%d', foo.created) = bar.day
    

    Results:

    2011-01-02|4.0
    2011-02-02|5.5
    2011-03-02|2.5
    

    NOTE – this is probably fairly inefficient, due to all the strftimes being done (I’m assuming no index can be used here).

    NOTE 2 – This query doesn’t deal with intervals other than exactly one month, do anything special if two records have the same date, or recognize when there are gaps in the the data (example: if the 2011-02-02 date was missing, it would still return the 2011-03-02 date).

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

Sidebar

Related Questions

I'm try to insert values into my sqlite table using a python script. It
I can't get SQLite Driver working in my sessionfactory. I downloaded SQLite 1.0.48 from
What is the approach to get SQLite-ruby working in IronRuby?
What are some best practices to keep in mind when working extensively with SQLite
I'm working on setting up a simple SQLite database to access via Python. So
I'm working with a sqlite database, using python/django. I would need to have my
I am working on making a new SQLite database. Obviously for a number of
I am working on Mac OS X, I want to create a new SQLite
I've got a flex/air app I've been working on, it uses a local sqlite
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch

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.