Converting Date Format to serial date

4 views (last 30 days)
I have a data set ( Sourced originally from NASA, GISS) which includes the date (in what i think is decimal date?!) and the northern hemisphere monthly temperature anomaly. Below is a section of the date:
Date Temp Ann
1880.0000 -0.404500
1880.0834 -0.570571
1880.1666 -0.313143
1880.2500 -0.360071
1880.3334 -0.113643
1880.4166 -0.209643
1880.5000 -0.230857
1880.5834 -0.296357
1880.6666 -0.282214
1880.7500 -0.401439
1880.8334 -0.505396
1880.9166 -0.417626
1881.0000 -0.344500
1881.0834 -0.280571
1881.1666 -0.113143
I need to convert the date into matlab serial date. I've tried datenum which obviously will not work on this format.
In all honesty im not 100% sure what the format actually is.
Any help in recognising the correct format and how to convert it would be greatly appreciated.

Accepted Answer

Star Strider
Star Strider on 25 Nov 2022
I’m not certain what the decimals are, however they appear to be sequential so they may be fractions of a year.
Unfortunately datetime isn’t set up for years and fraction-of-years, at least not that I can determine. It would be nice to have that option. (I experimented with the ‘epoch’ options, however they produced reults that were obviously wrong.)
A = [1880.0000 -0.404500
1880.0834 -0.570571
1880.1666 -0.313143
1880.2500 -0.360071
1880.3334 -0.113643
1880.4166 -0.209643
1880.5000 -0.230857
1880.5834 -0.296357
1880.6666 -0.282214
1880.7500 -0.401439
1880.8334 -0.505396
1880.9166 -0.417626
1881.0000 -0.344500
1881.0834 -0.280571
1881.1666 -0.113143];
DIY = day(datetime('31-Dec-1880'),'dayofyear') % Leap Year!
DIY = 366
DOY = rem(A(:,1),1)*DIY;
HOD = rem(DOY,1)*24;
DT = datetime([fix(A(:,1)) zeros(size(A(:,1)))+1 fix(DOY)+1 fix(HOD) fix(rem(HOD,1)*60) fix(rem(HOD,1)*60)], 'Format','yyyy-MMM-dd HH:mm:ss')
DT = 15×1 datetime array
1880-Jan-01 00:00:00 1880-Jan-31 12:35:35 1880-Mar-01 23:24:24 1880-Apr-01 12:00:00 1880-May-02 00:35:35 1880-Jun-01 11:24:24 1880-Jul-02 00:00:00 1880-Aug-01 12:35:35 1880-Aug-31 23:24:24 1880-Oct-01 12:00:00 1880-Nov-01 00:35:35 1880-Dec-01 11:24:24 1881-Jan-01 00:00:00 1881-Jan-31 12:35:35 1881-Mar-02 23:24:24
This appears to produce the correct result, although I did not rigorously check it.
NOTE to MathWorks — Would it be possible to implement this as an option?
.
  4 Comments
Laura
Laura on 29 Nov 2022
Thank you for your help Star Strider!
Star Strider
Star Strider on 29 Nov 2022
As always, my pleasure!
One note about the precision of the times is that with decimal precison of years:
fprintf('Time Precision = %.2f minutes\n', 366*24*60 * 1E-4)
Time Precision = 52.70 minutes
So the time is essentially in 52.7 minute or 0.878 hour intervals.
.

Sign in to comment.

More Answers (0)

Categories

Find more on Dates and Time 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!