MATLAB: Datenum conversion problem

datenumMATLAB

I read in a Julian day array, yy. Strangely I got a different date string when I use different reference date, such as yyt=yy-datenum(2014, 1, 1) and yyt=yy-datenum(2000, 1, 1). Could somebody explain why? Thanks.

Best Answer

First, is yy really a Julian day array, or is it a Day Of the Year (DOY) number array? There are quite a few websites etc out there that erroneously refer to DOY numbers as Julian Day numbers.
Second, if yy really is a Julian day array, be advised that datenum does NOT return a Julian day number. It returns the days (and fractions of day) since January 0, 0000.
Maybe you could clarify what you are trying to do and why you are using the calculations you show above?
EDIT:
To convert between Julian Day numbers and Serial Date Numbers you can use the following relationship:
Julian_Day = Serial_Date_Number + 1721058.5
So in your case, if yy are Julian Day values and you want to convert them to Serial Date Numbers (i.e., compatible with the datenum function), then
yy_sdn = yy - 1721058.5; % Convert Julian Day to Serial Date Number
yy_dv = datevec(yy_sdn); % Convert Serial Date Number to Datevec
Keep in mind that this is a straight conversion with no assumptions about UTC or TT etc. E.g., if you start with Julian Day UTC values, you will get UTC datevec values as a result. If you start with Julian Day TT values, you will get TT datevec values as a result. Etc.