Kindly help me to convert this into local date format

L
Lucas · Dec 10, 2020 · 1.9K views
Question
How i can convert the list of date/time in to my local date format and let me know which format is it? Example: From 1992.752225 1992.765914 1992.779603 ................2018.460643 to dd/mm/yyyy or 'dd-mm-yyyy HH:MM:SS'
Expert Answer
Profile picture of John Williams
John Williams PhD Expert
Answered Nov 20, 2025
d = [1992.752225; 1992.765914; 1992.779603; 2018.460643];
datetime(floor(d), 1, 1) + years(mod(d,1))
ans = 4×1 datetime array
01-Oct-1992 17:52:08 06-Oct-1992 17:51:51 11-Oct-1992 17:51:34 18-Jun-2018 05:54:49
However, I would be concerned about the difference between years() -- which uses fixed-length years -- and calendar years.
 
fd = floor(d);
datetime(fd, 1, 1) + (d-fd) .* days(365+leapyear(fd))
ans = 4×1 datetime array
02-Oct-1992 07:32:39 07-Oct-1992 07:47:18 12-Oct-1992 08:01:57 18-Jun-2018 03:13:57
The similarities of the first three times in the first version suggest to me that the time system is using fixed length years --- but that can make it difficult to figure out how to handle the leapyear. Some time systems like that just remove the leap day; if you are using one of those then for entries for which leapyear() is true and the date is after Feb 28, you have to add one day.
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!