How to extract month or year or day of the month from an Sqlite database column which is created as DATE format?
I have an sqlite db. I need to make a comparison of the current date's month and day with a column from the database which is created as DATE format.
For example I have the following code:
import sqlite3
from datetime import datetime
current_month = datetime.today().month
current_day = datetime.today().day
conn = sqlite3.connect('mydb.db')
conn.row_factory = sqlite3.Row
c = conn.cursor()
c.execute('SELECT * FROM hr')
for data in c.fetchall():
emp_date = data['employement_date']
print(emp_date) #This prints the dates from that column formatted as YYYY-MM-DD.
So I want to make a comparison like;
if current_day == empdate(date) or current_month == empdate(month) print("True")
so the empdate(date) expression and empdate(month) expression are just an example. I'm trying to find the right extraction code to replace these examples.
The type of the emp_date is
Thanks.
Comments
Post a Comment