How to store partially known datetimes
조회 수: 1 (최근 30일)
이전 댓글 표시
What is the best way in MATLAB to deal with partially known date times?
I have a list of dates and times as part of a database. For most, I know the full date and time, but for many I only know down to the day, or month, or even just year. Currently, I have them stored in a table seperated by year, month, day, and time, but I would much prefer a single field if possible.
Is there a way to use the datetime or other datatype in MATLAB to convey that information about the date and time could be missing?
댓글 수: 1
Walter Roberson
2020년 10월 7일
Unfortunately, datetime objects only have specific complete datetimes, or else the Not A Time object, NaT .
You could fill out the datetime objects as far as you know, using the "start" of the date (e.g., Jan 1, 00:00:00 of the year), and also keep a numeric encoding of which information is missing (perhaps an enumeration)
채택된 답변
Stephen23
2020년 10월 8일
편집: Stephen23
2020년 10월 19일
I don't believe that information can be encoded inside one datetime object, so you will have to use another object or variable to hold that information (which could be another datetime).
Here are a few idea (all examples are known down to the nearest minute):
- use a calendarduration or duration object to store the lowest known unit, e.g. duration 00:01:00.000
- similarly with a date vector, e.g. [0,0,0,0,1,0] (downside: not scalar, but perhaps slightly easier to work with)
- similarly with a logical vector, e.g. [false,false,false,false,true,false] (downside: not scalar)
- store one single integer index/count of the known units, e.g. 5 would indicate data is known to the nearest minute.
I would start with the fourth option (on the basis that this is by far the simplest) and see if that could work for your algorithm.
댓글 수: 4
Siddharth Bhutiya
2020년 10월 23일
Based on this information, as you had mentioned in your earlier comment a custom class seems to be the way to go here. Your class can have 2 properties, a datetime and an 'estimate' metadata. What you choose as the datatype for your 'estimate' metadata would depend on your use case. For example, let's say, if the data is such that even if the time is provided, it still can be an estimate, i.e. it can be that time +/- x hrs, then it makes sense to store the 'estimate' as calendarDuration or duration. However, if the data is such that whatever is provided is accurate and only the missing pieces are unknown/estimates then you can store the 'estimate' as a scalar categorical that notes the last known unit ('day','month','hour',etc.), as Stephen mentioned above.
You mentioned that it is for a database, then maybe instead of complicating things by creating a class, you might be better off having 2 fields in your table one for the datetime and one for the 'estimate'.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!