Optimal way to store datetime values in SQLite database (Delphi)

后端 未结 5 1271
无人及你
无人及你 2021-02-08 16:29

I will be storing datetime values in an SQLite database (using Delphi and the DISqlite library). The nature of the db is such that it will never need to be transferred between c

5条回答
  •  爱一瞬间的悲伤
    2021-02-08 16:34

    If your concern is only human readable format at database level, you can store two separate fields, for example:

    DELPHI_DATE REAL (DOUBLE, if possible, but I don't know SQLite), Indexed. All your programmatic queries and comparisons should use this field.

    HUMAN_READABLE_DATE Varchar(23) with format 'YYYY-MM-DD HH:MM:SS.SSS'. Maybe indexed (if really necessary). Majority of human input queries should include this field and you can use (as said by others) SQLite date functions.

    It has some drawbacks:

    • Space consumption at database and network traffic grows,
    • insert operations will take a bit more because necessary conversion,
    • no automatic synch between values if updated outside your program

    If it is suitable for your particular needs, is up to you.

提交回复
热议问题