It doesn't matter when the time is entered or what it is supposed to 
reflect.  The best option -- by a wide margin -- for storing any time 
values is in a TIMESTAMP column, and for storing date+time values is in a 
DATETIME column.  These types of columns/fields/formats exist to streamline 
data storage and leverage numerous operations on the database and in your 
application.

Even though you will only show the user an option of 12hours and am/pm, on 
the backend you should be storing the time in a 24hour native time object; 
if there is a date associated, you should be storing it in a timestamp.  
That will allow you to easily query records with these fields in the future.

Timestamp/Datetime:
   * Python https://docs.python.org/3/library/datetime.html#datetime-objects
 
   * SqlAlchemy 
https://docs.sqlalchemy.org/en/13/core/type_basics.html?highlight=timestamp#sqlalchemy.types.DateTime

Time:
   * Python - https://docs.python.org/3/library/datetime.html#time-objects
   * SqlAlchemy Column - 
https://docs.sqlalchemy.org/en/13/core/type_basics.html?highlight=timestamp#sqlalchemy.types.Time

If you feel a strong need to handle this otherwise, you can use an Enum (
https://docs.sqlalchemy.org/en/13/core/type_basics.html?highlight=timestamp#sqlalchemy.types.Enum)
 
column to constrain the am/pm options.  You can also just use a string 
column and enforce the selection with constraints.

Your best path forward, however, is convert the user-input into a python 
Time or DateTime object and store that object in the database; then you can 
construct the widgets for "display/edit" by setting their defaults to be 
the day/month/year/hour/minute of the datetime field in your sqlalchemy 
object.



-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/50f736a5-4dd3-4537-9530-7b990eb64473%40googlegroups.com.

Reply via email to