I want to change the hour format from 24 to 12. This is an attendance project and the following python code linked with HTML to show up the attendance from the database. And this is the code
from flask import Flask, render_template, request
import sqlite3
from datetime import datetime
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html', selected_date='', no_data=False)
@app.route('/attendance', methods=['POST'])
def attendance():
selected_date = request.form.get('selected_date')
selected_date_obj = datetime.strptime(selected_date, '%Y-%m-%d')
formatted_date = selected_date_obj.strftime('%Y-%m-%d')
conn = sqlite3.connect('attendance.db')
cursor = conn.cursor()
cursor.execute("SELECT name, time FROM attendance WHERE date = ?", (formatted_date,))
attendance_data = cursor.fetchall()
conn.close()
if not attendance_data:
return render_template('index.html', selected_date=selected_date, no_data=True)
return render_template('index.html', selected_date=selected_date, attendance_data=attendance_data)
if __name__ == '__main__':
app.run(debug=True)
I have tried to do it by myself but I can’t. I also tried with GPTs, but that was also a bug.
New contributor
It’s Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.