How to convert dates into Julian dates?
Show older comments
I have read the dates in yyyymmdd format as follows;
dates = 20230409 20230414 20230504 20230514 20230519 20230608 20230613 20230723 20230817 20230827 20230901 20231006 20231011 20231026 20231115 20231125 20231205 20231210 20240129
I want to convert these dates into julian dates. Please suggest me how to do it?
I will appreciate your kind cooperation.
Deva
1 Comment
Make sure that you import the data as DATETIME, then use:
Do not import dates as scalar numerics whose digits just happen to look like those of some unrelated date units.
Accepted Answer
More Answers (1)
Based on your comment that you are expecting numbers in the range of 273,287,298, etc., if what you are after is actually "day of year" and not "Julian Date", then
dates = [20230409 20230414 20230504 20230514 20230519 20230608 20230613 20230723 20230817 20230827 20230901 20231006 20231011 20231026 20231115 20231125 20231205 20231210 20240129];
gdt = datetime(dates,"ConvertFrom","yyyymmdd") % Gregorian
days(gdt - datetime(year(gdt),1,1)) + 1 % day of year, with Jan 1 being day number 1
I am aware that some fields of study refer to "day of year" as "Julian Date", but this is incorrect terminology.
4 Comments
Devendra
on 8 Apr 2024
You don't need to write your last expression. Just ask the day function for the 'dayofyear'.
dates = [20230409 20230414 20230504 20230514 20230519 ...
20230608 20230613 20230723 20230817 20230827 ...
20230901 20231006 20231011 20231026 20231115 ...
20231125 20231205 20231210 20240129];
gdt = datetime(dates,"ConvertFrom","yyyymmdd"); % Gregorian
day(gdt, 'dayofyear')
Devendra
on 8 Apr 2024
James Tursa
on 8 Apr 2024
@Steven Lord I thought I remembered there was a function for this but couldn't find it in datetime methods. Didn't think to look in day( ) doc. Thanks for the update.
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!