开发者

DateTime + 2x Time vs. DateTime + Duration for storing time

开发者 https://www.devze.com 2023-02-21 09:49 出处:网络
I\'m trying to implement a ReservationController which is responsible for taking reservations of something for a specific time range. So far I guessed using one column for the Date (DateTime) and two

I'm trying to implement a ReservationController which is responsible for taking reservations of something for a specific time range. So far I guessed using one column for the Date (DateTime) and two columns for the time span (2x Time) in the database would be a good idea. Especially when it comes to queries on date, this approach is easier because I know, that the DateTime column is always set to 12am. So I just query DateTime.Today for instance. But now I'm getting into trouble with reservations which are passing t开发者_运维技巧he day border (eg. Today 22pm - Tomorrow 1am). Could you please give me some advice what is a common solution for this problem (what database schema I should use)?

regards


I would have thought just two DateTimes would be enough? You can still query whether start datetime or end datetime is today (i.e >= today midnight and < tomorrow midnight).

Perhaps I am missing something - were there other queries you need to do, or were you worried about optimisation of this query? It should be fine, if you add one or more indexes for the DateTime columns.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号