How to convert serial number to date number
Show older comments
I have this serial number 21123:23010 that I want to convert into date number 'DD MM YYYY'.
I have tried this cod but didn't work properly. It appears as a text not in columm
T=datestr(21123:23010,'yyyy-mm')
2 Comments
Pranavkumar Mallela
on 12 Jul 2023
Hi, can you elaborate on what the desired result is? The code you provided seems to be returning a 1888 x 10 'char' matrix. Thanks.
"I have this serial number 21123:23010 "
Those are not MATLAB serial date numbers (unless you are working with years 57AD to 62AD... which is very unlikely).
It might be some other kind of serial date number (if so you need to give us the unit and epoch).
It looks like it might be some integers whose digits just happen to correspond to the digits of some dates using completely different units. For example, a 2-digit year and 3-digit day of the year.
In any case, the best step is to save your data in a MAT file and upload it here by clicking the paperclip button. And give us the exact definition of how those values encode the dates.
Accepted Answer
More Answers (1)
The CMEMS documentation gives several possible time units, one of them is
% julian_day_unit = "days since 1950-01-01 00:00:00" ;
V = [21123,23010];
D = datetime(1950,1,1,'Format','u-MM-dd HH:mm:ss') + caldays(V)
This makes it clear that you downloaded data for Nov 2007 through to Dec 2012.
We can check this conversion using the adjacent information fields given in the documentation, which conveniently gives one date both in calendar and "julian" formats. This makes is easy to confirm this method:
% field_date = "2020-12-31 00:00:00" ;
% field_julian_date = 25932.f ;
D = datetime(1950,1,1,'Format','u-MM-dd HH:mm:ss') + caldays(25932)
In contrast any code that returns the years 57AD and 62 AD is complete nonsense. The dates 30th of Oct/Dec are also wrong.
1 Comment
Peter Perkins
on 17 Jul 2023
This is consistent with my other comment, except for the 1-based vs. 0-based counting convention. Dunno which is right, I chose 1-based, but you're probably right.
Categories
Find more on Time Series Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!