不完整日期策略 [英] Strategy for Incomplete Dates
问题描述
我们希望使用一个date属性/列,并能够在日期排序。
任何建议?
将日期存储为整数 - - yyyymmdd。
然后,您可以将任何未输入的任何月份或日期组件清零
仅年:1954 => 19540000
年月份:2004年4月=> 20040400
2011年1月1日=> 20110101
当然,我假设您不需要存储任何时间的日期信息。 p>
然后,您可以创建一个结构来将此逻辑与包含已设置的粒度级别的有用属性相关联,相关的System.DateTime等。
编辑:排序应该很好地工作
Working on an application where we would like the user to be able to enter incomplete dates.
In some cases there will only be a year - say 1854, or there might be a year and a month, for example March 1983, or there may be a complete date - 11 June 2001.
We'd like a single 'date' attribute/column - and to be able to sort on date.
Any suggestions?
Store the date as an integer -- yyyymmdd.
You can then zero out any month or day component that has not been entered
Year only: 1954 => 19540000
Year & Month: April 2004 => 20040400
January 1st, 2011 => 20110101
Of course I am assuming that you do not need to store any time of day information.
You could then create a struct to encapsulate this logic with useful properties indicating which level of granularity has been set, the relevant System.DateTime, etc
Edit: sorting should then work nicely as well
这篇关于不完整日期策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!