Best way to store time above 24:00:00 in postgresql?

后端 未结 2 690
广开言路
广开言路 2021-01-14 00:42

I\'m storing GTFS feeds into a SQL database and some times are expected to be stored above the 24:00:00 cap on time values. For example, some trains run at 12:30AM, but are

2条回答
  •  长发绾君心
    2021-01-14 00:55

    Suggest to use int for that... your value could be:

    Sec + Min * 60 + Hour * 3600
    

    For the 24:30:00, you will get 88200.

    When loading your value from DB, you could reverse your value by simple math equation:

    Hour = int(value / 3600)
    Min  = int(value % 3600 / 60)
    Sec  = value % 3600 % 1800
    

提交回复
热议问题