Datenum conversion problem?

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.

1 Comment

I want to get date vectors from yy. So, if yy is a Julian day array, I should always use January 0, 0000 as a reference date to get right date vectors, am I right? Thanks.

Sign in to comment.

 Accepted Answer

James Tursa
James Tursa on 24 Aug 2015
Edited: James Tursa on 25 Aug 2015
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.

2 Comments

I didn't get a right date vector following this calculation. Does that mean yy is a year number array? How do I obtain a right date in that case? Thanks.
Please provide a sample input number and the date you expected to get for output for that particular number, and we can help determine what the input number really is. If it is a DOY number, then you would need to know the year involved in order to get the date. E.g., something like this might be what you need if you knew the year was 2000:
mydate = datenum(2000, 1, 1) + DOY - 1;

Sign in to comment.

More Answers (0)

Categories

Products

Tags

Asked:

on 24 Aug 2015

Edited:

on 26 Aug 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!