SQLite Sample table with Date column





Creating SQLite table to use date query by using today's date as base date in Colab Platform


Place part 1 and part 2 in the same sequence and execute. New Database will be created if Path is correct and database name (file name ) is new.

part 1 ( Create dt_table table )
import sqlite3
my_path='F:\\testing\\sqlite\\my_db.db' #Change the path of your database  
try:
    my_conn = sqlite3.connect(my_path) # 
except sqlite3.Error as my_error:
  print("error: ",my_error)
else:
    print("Connected to database successfully")
r_set=my_conn.execute("CREATE TABLE IF NOT EXISTS dt_table ( \
  record_id varchar(4) NOT NULL, \
  date text NOT NULL, \
  `month-year` varchar(10) NOT NULL)")
my_conn.commit()
part 2 ( adding Data to Table ) Note that Part 2 changes every day ( dynamic ) based on the current date. We are using here previous 15 days and next 15 days as data for our table. This is required to run the queries based on today’s date.

Example : Collect last 5 days records. Collect records of present week , collect records starting from 1st of previous month.

Here is a sample ipynb file used to create the database with sample data. Note that the data tuple changes every day.
View & Download sample ipynb file (.html format)

Sqlite Date Query insert update selectOrder By
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer