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  
    my_conn = sqlite3.connect(my_path) # 
except sqlite3.Error as my_error:
  print("error: ",my_error)
    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)")
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
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net


    Post your comments , suggestion , error , requirements etc here

    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 FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer