How to convert column datetime (yyyy-mm-dd HH:MM:DD.000) into MJD and decyear?

4 views (last 30 days)
I have column datetime (yyyy-mm-dd HH:MM:DD.000) data in *txt format. I want to convert into MJD and decyear. How to do it?
opts = detectImportOptions('j3c001_delimited.txt');
readtable('j3c001_delimited.txt',opts)
ans = 1843×29 table
cyc pass time lat lon alt_gdrf dist dryERA invbar_mog2d ionoSmooth ionoGIM mssC15 mssDTU18 range_ku rfo ssbCLS ssbCLSmle3 ssbTran t_loadFES14 t_loadGOT410 t_ocFES14 t_ocGOT410 t_pole t_solid wet_ecm wet_era wet_rad SSH_ERA_BRAT SLA_ERA_BRAT ___ ____ _______________________ _______ ______ __________ _____ _______ ____________ __________ _______ ______ ________ __________ _______ _______ __________ _______ ___________ ____________ _________ __________ _______ _______ _______ _______ _______ ____________ ____________ 1 25 2016-02-18 09:21:18.461 -13 115 1.3405e+06 452.8 -2.2999 -0.0003 -0.0792 -0.0816 9.2631 9.2436 1.3405e+06 -0.0198 -0.0588 -0.0884 -0.0675 -0.034 -0.0334 0.5958 0.569 0.0026 -0.1218 -0.2237 -0.241 -0.2303 9.1521 -0.111 1 25 2016-02-18 09:21:18.045 -12.667 115 1.3405e+06 428 -2.2999 -0.0011 -0.0811 -0.0824 10.655 10.64 1.3405e+06 -0.0198 -0.0593 -0.0904 -0.0679 -0.034 -0.0334 0.5973 0.571 0.0026 -0.1214 -0.2277 -0.2428 -0.2319 10.499 -0.1565 1 216 2016-02-25 20:25:25.802 -6.6667 115 1.3403e+06 24.1 -2.307 -0.0085 -0.0129 -0.0206 39.706 39.705 1.3403e+06 -0.0198 -0.0494 -0.0795 -0.0593 0.01 0.0101 -0.0508 -0.046 0.0012 0.0607 -0.3902 -0.3902 -0.3708 39.687 -0.0188 1 216 2016-02-25 20:25:25.727 -6.3333 115 1.3403e+06 46 -2.3072 -0.0108 -0.0118 -0.0206 39.911 39.907 1.3403e+06 -0.0198 -0.0481 -0.0792 -0.0584 0.0094 0.0095 -0.036 -0.0179 0.0012 0.0614 -0.3928 -0.3937 -0.3716 39.919 0.0073 1 203 2016-02-25 08:10:25.607 -5.3333 115 1.3396e+06 53 -2.3055 -0.0229 -0.0844 -0.0888 43.844 43.819 1.3396e+06 -0.0198 -0.0506 -0.0785 -0.0604 -0.0013 -0.001 0.1498 0.1698 0.001 0.0689 -0.3905 -0.384 -0.4399 43.906 0.0615 1 203 2016-02-25 08:10:25.191 -5 115 1.3396e+06 54.3 -2.3057 -0.0233 -0.0855 -0.0891 44.803 44.789 1.3396e+06 -0.0198 -0.0545 -0.0781 -0.0637 -0.0017 -0.0013 0.1651 0.1765 0.0009 0.0683 -0.3924 -0.3837 -0.3774 44.89 0.0868 1 114 2016-02-21 20:46:21.443 9 115 1.3404e+06 128.5 -2.3127 -0.0291 -0.0074 -0.0192 36.754 36.735 1.3403e+06 -0.0198 -0.0605 -0.0855 -0.0686 0.0207 0.0218 -0.5641 -0.586 -0.0018 -0.1459 -0.2751 -0.2669 -0.2791 36.669 -0.0851 1 114 2016-02-21 20:45:21.859 9.3333 115 1.3404e+06 104.3 -2.3128 -0.0299 -0.0081 -0.0191 36.04 36.028 1.3403e+06 -0.0198 -0.0608 -0.0839 -0.0691 0.0208 0.0219 -0.5618 -0.5824 -0.0018 -0.1449 -0.2754 -0.2645 -0.2822 35.966 -0.0745 1 51 2016-02-19 09:51:19.940 10.333 115 1.3399e+06 75 -2.31 -0.044 -0.0883 -0.1252 33.266 33.258 1.3399e+06 -0.0198 -0.0671 -0.0922 -0.0744 -0.0258 -0.0276 0.4565 0.491 -0.0021 -0.1284 -0.2189 -0.211 -0.2242 33.158 -0.1078 1 51 2016-02-19 09:51:19.524 10.667 115 1.3399e+06 51.6 -2.3102 -0.0449 -0.0882 -0.1251 33.065 33.057 1.3399e+06 -0.0198 -0.0733 -0.0942 -0.0793 -0.0258 -0.0276 0.4563 0.4908 -0.0022 -0.1276 -0.2165 -0.2084 -0.2215 32.963 -0.1013 1 25 2016-02-18 09:21:18.102 -12.667 115.33 1.3404e+06 411.5 -2.3 -0.0015 -0.0826 -0.0829 11.533 11.519 1.3404e+06 -0.0198 -0.0614 -0.0903 -0.0699 -0.034 -0.0334 0.5984 0.5722 0.0026 -0.1212 -0.2298 -0.244 -0.2377 11.4 -0.1328 1 25 2016-02-18 09:21:18.686 -12.333 115.33 1.3404e+06 386.7 -2.3 -0.0023 -0.0848 -0.0838 12.438 12.421 1.3404e+06 -0.0198 -0.058 -0.0886 -0.0667 -0.0339 -0.0333 0.5998 0.5739 0.0025 -0.1208 -0.2329 -0.2457 -0.2429 12.312 -0.1266 1 25 2016-02-18 09:21:18.817 -12 115.33 1.3404e+06 347.3 -2.3001 -0.0034 -0.0866 -0.0851 12.967 12.957 1.3404e+06 -0.0198 -0.0586 -0.0901 -0.0672 -0.0337 -0.0332 0.6018 0.5764 0.0025 -0.1202 -0.2387 -0.247 -0.2442 12.897 -0.0703 1 25 2016-02-18 09:21:18.892 -11.667 115.33 1.3403e+06 324 -2.3002 -0.004 -0.0869 -0.0859 12.734 12.719 1.3403e+06 -0.0198 -0.0566 -0.0865 -0.0655 -0.0336 -0.0331 0.6027 0.5775 0.0024 -0.1199 -0.2425 -0.2474 -0.2414 12.67 -0.0642 1 216 2016-02-25 20:25:25.176 -7.6667 115.33 1.3404e+06 48.6 -2.3072 -0.0002 -0.0241 -0.0207 35.22 35.199 1.3404e+06 -0.0198 -0.0064 -0.0392 -0.02 0.0134 0.0132 -0.1069 -0.0604 0.0014 0.0574 -0.3976 -0.3615 -0.3628 35.241 0.0215 1 216 2016-02-25 20:25:25.045 -7.3333 115.33 1.3404e+06 34.7 -2.307 -0.0007 -0.0153 -0.0207 36.918 36.91 1.3404e+06 -0.0198 -0.0091 -0.0477 -0.0262 0.0121 0.012 -0.0958 -0.0706 0.0013 0.0585 -0.3925 -0.3684 -0.3694 36.91 -0.0076

Accepted Answer

Star Strider
Star Strider on 7 Sep 2022
The mjuliandate and decyear functions are part of the Aerospace Toolbox (that I do not have, however is available online here) —
opts = detectImportOptions('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1119295/j3c001_delimited.txt');
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1119295/j3c001_delimited.txt',opts)
T1 = 1843×29 table
cyc pass time lat lon alt_gdrf dist dryERA invbar_mog2d ionoSmooth ionoGIM mssC15 mssDTU18 range_ku rfo ssbCLS ssbCLSmle3 ssbTran t_loadFES14 t_loadGOT410 t_ocFES14 t_ocGOT410 t_pole t_solid wet_ecm wet_era wet_rad SSH_ERA_BRAT SLA_ERA_BRAT ___ ____ _______________________ _______ ______ __________ _____ _______ ____________ __________ _______ ______ ________ __________ _______ _______ __________ _______ ___________ ____________ _________ __________ _______ _______ _______ _______ _______ ____________ ____________ 1 25 2016-02-18 09:21:18.461 -13 115 1.3405e+06 452.8 -2.2999 -0.0003 -0.0792 -0.0816 9.2631 9.2436 1.3405e+06 -0.0198 -0.0588 -0.0884 -0.0675 -0.034 -0.0334 0.5958 0.569 0.0026 -0.1218 -0.2237 -0.241 -0.2303 9.1521 -0.111 1 25 2016-02-18 09:21:18.045 -12.667 115 1.3405e+06 428 -2.2999 -0.0011 -0.0811 -0.0824 10.655 10.64 1.3405e+06 -0.0198 -0.0593 -0.0904 -0.0679 -0.034 -0.0334 0.5973 0.571 0.0026 -0.1214 -0.2277 -0.2428 -0.2319 10.499 -0.1565 1 216 2016-02-25 20:25:25.802 -6.6667 115 1.3403e+06 24.1 -2.307 -0.0085 -0.0129 -0.0206 39.706 39.705 1.3403e+06 -0.0198 -0.0494 -0.0795 -0.0593 0.01 0.0101 -0.0508 -0.046 0.0012 0.0607 -0.3902 -0.3902 -0.3708 39.687 -0.0188 1 216 2016-02-25 20:25:25.727 -6.3333 115 1.3403e+06 46 -2.3072 -0.0108 -0.0118 -0.0206 39.911 39.907 1.3403e+06 -0.0198 -0.0481 -0.0792 -0.0584 0.0094 0.0095 -0.036 -0.0179 0.0012 0.0614 -0.3928 -0.3937 -0.3716 39.919 0.0073 1 203 2016-02-25 08:10:25.607 -5.3333 115 1.3396e+06 53 -2.3055 -0.0229 -0.0844 -0.0888 43.844 43.819 1.3396e+06 -0.0198 -0.0506 -0.0785 -0.0604 -0.0013 -0.001 0.1498 0.1698 0.001 0.0689 -0.3905 -0.384 -0.4399 43.906 0.0615 1 203 2016-02-25 08:10:25.191 -5 115 1.3396e+06 54.3 -2.3057 -0.0233 -0.0855 -0.0891 44.803 44.789 1.3396e+06 -0.0198 -0.0545 -0.0781 -0.0637 -0.0017 -0.0013 0.1651 0.1765 0.0009 0.0683 -0.3924 -0.3837 -0.3774 44.89 0.0868 1 114 2016-02-21 20:46:21.443 9 115 1.3404e+06 128.5 -2.3127 -0.0291 -0.0074 -0.0192 36.754 36.735 1.3403e+06 -0.0198 -0.0605 -0.0855 -0.0686 0.0207 0.0218 -0.5641 -0.586 -0.0018 -0.1459 -0.2751 -0.2669 -0.2791 36.669 -0.0851 1 114 2016-02-21 20:45:21.859 9.3333 115 1.3404e+06 104.3 -2.3128 -0.0299 -0.0081 -0.0191 36.04 36.028 1.3403e+06 -0.0198 -0.0608 -0.0839 -0.0691 0.0208 0.0219 -0.5618 -0.5824 -0.0018 -0.1449 -0.2754 -0.2645 -0.2822 35.966 -0.0745 1 51 2016-02-19 09:51:19.940 10.333 115 1.3399e+06 75 -2.31 -0.044 -0.0883 -0.1252 33.266 33.258 1.3399e+06 -0.0198 -0.0671 -0.0922 -0.0744 -0.0258 -0.0276 0.4565 0.491 -0.0021 -0.1284 -0.2189 -0.211 -0.2242 33.158 -0.1078 1 51 2016-02-19 09:51:19.524 10.667 115 1.3399e+06 51.6 -2.3102 -0.0449 -0.0882 -0.1251 33.065 33.057 1.3399e+06 -0.0198 -0.0733 -0.0942 -0.0793 -0.0258 -0.0276 0.4563 0.4908 -0.0022 -0.1276 -0.2165 -0.2084 -0.2215 32.963 -0.1013 1 25 2016-02-18 09:21:18.102 -12.667 115.33 1.3404e+06 411.5 -2.3 -0.0015 -0.0826 -0.0829 11.533 11.519 1.3404e+06 -0.0198 -0.0614 -0.0903 -0.0699 -0.034 -0.0334 0.5984 0.5722 0.0026 -0.1212 -0.2298 -0.244 -0.2377 11.4 -0.1328 1 25 2016-02-18 09:21:18.686 -12.333 115.33 1.3404e+06 386.7 -2.3 -0.0023 -0.0848 -0.0838 12.438 12.421 1.3404e+06 -0.0198 -0.058 -0.0886 -0.0667 -0.0339 -0.0333 0.5998 0.5739 0.0025 -0.1208 -0.2329 -0.2457 -0.2429 12.312 -0.1266 1 25 2016-02-18 09:21:18.817 -12 115.33 1.3404e+06 347.3 -2.3001 -0.0034 -0.0866 -0.0851 12.967 12.957 1.3404e+06 -0.0198 -0.0586 -0.0901 -0.0672 -0.0337 -0.0332 0.6018 0.5764 0.0025 -0.1202 -0.2387 -0.247 -0.2442 12.897 -0.0703 1 25 2016-02-18 09:21:18.892 -11.667 115.33 1.3403e+06 324 -2.3002 -0.004 -0.0869 -0.0859 12.734 12.719 1.3403e+06 -0.0198 -0.0566 -0.0865 -0.0655 -0.0336 -0.0331 0.6027 0.5775 0.0024 -0.1199 -0.2425 -0.2474 -0.2414 12.67 -0.0642 1 216 2016-02-25 20:25:25.176 -7.6667 115.33 1.3404e+06 48.6 -2.3072 -0.0002 -0.0241 -0.0207 35.22 35.199 1.3404e+06 -0.0198 -0.0064 -0.0392 -0.02 0.0134 0.0132 -0.1069 -0.0604 0.0014 0.0574 -0.3976 -0.3615 -0.3628 35.241 0.0215 1 216 2016-02-25 20:25:25.045 -7.3333 115.33 1.3404e+06 34.7 -2.307 -0.0007 -0.0153 -0.0207 36.918 36.91 1.3404e+06 -0.0198 -0.0091 -0.0477 -0.0262 0.0121 0.012 -0.0958 -0.0706 0.0013 0.0585 -0.3925 -0.3684 -0.3694 36.91 -0.0076
T1.time = mjuliandate(T1.time)
T1 = 1843×29 table
cyc pass time lat lon alt_gdrf dist dryERA invbar_mog2d ionoSmooth ionoGIM mssC15 mssDTU18 range_ku rfo ssbCLS ssbCLSmle3 ssbTran t_loadFES14 t_loadGOT410 t_ocFES14 t_ocGOT410 t_pole t_solid wet_ecm wet_era wet_rad SSH_ERA_BRAT SLA_ERA_BRAT ___ ____ _____ _______ ______ __________ _____ _______ ____________ __________ _______ ______ ________ __________ _______ _______ __________ _______ ___________ ____________ _________ __________ _______ _______ _______ _______ _______ ____________ ____________ 1 25 57436 -13 115 1.3405e+06 452.8 -2.2999 -0.0003 -0.0792 -0.0816 9.2631 9.2436 1.3405e+06 -0.0198 -0.0588 -0.0884 -0.0675 -0.034 -0.0334 0.5958 0.569 0.0026 -0.1218 -0.2237 -0.241 -0.2303 9.1521 -0.111 1 25 57436 -12.667 115 1.3405e+06 428 -2.2999 -0.0011 -0.0811 -0.0824 10.655 10.64 1.3405e+06 -0.0198 -0.0593 -0.0904 -0.0679 -0.034 -0.0334 0.5973 0.571 0.0026 -0.1214 -0.2277 -0.2428 -0.2319 10.499 -0.1565 1 216 57444 -6.6667 115 1.3403e+06 24.1 -2.307 -0.0085 -0.0129 -0.0206 39.706 39.705 1.3403e+06 -0.0198 -0.0494 -0.0795 -0.0593 0.01 0.0101 -0.0508 -0.046 0.0012 0.0607 -0.3902 -0.3902 -0.3708 39.687 -0.0188 1 216 57444 -6.3333 115 1.3403e+06 46 -2.3072 -0.0108 -0.0118 -0.0206 39.911 39.907 1.3403e+06 -0.0198 -0.0481 -0.0792 -0.0584 0.0094 0.0095 -0.036 -0.0179 0.0012 0.0614 -0.3928 -0.3937 -0.3716 39.919 0.0073 1 203 57443 -5.3333 115 1.3396e+06 53 -2.3055 -0.0229 -0.0844 -0.0888 43.844 43.819 1.3396e+06 -0.0198 -0.0506 -0.0785 -0.0604 -0.0013 -0.001 0.1498 0.1698 0.001 0.0689 -0.3905 -0.384 -0.4399 43.906 0.0615 1 203 57443 -5 115 1.3396e+06 54.3 -2.3057 -0.0233 -0.0855 -0.0891 44.803 44.789 1.3396e+06 -0.0198 -0.0545 -0.0781 -0.0637 -0.0017 -0.0013 0.1651 0.1765 0.0009 0.0683 -0.3924 -0.3837 -0.3774 44.89 0.0868 1 114 57440 9 115 1.3404e+06 128.5 -2.3127 -0.0291 -0.0074 -0.0192 36.754 36.735 1.3403e+06 -0.0198 -0.0605 -0.0855 -0.0686 0.0207 0.0218 -0.5641 -0.586 -0.0018 -0.1459 -0.2751 -0.2669 -0.2791 36.669 -0.0851 1 114 57440 9.3333 115 1.3404e+06 104.3 -2.3128 -0.0299 -0.0081 -0.0191 36.04 36.028 1.3403e+06 -0.0198 -0.0608 -0.0839 -0.0691 0.0208 0.0219 -0.5618 -0.5824 -0.0018 -0.1449 -0.2754 -0.2645 -0.2822 35.966 -0.0745 1 51 57437 10.333 115 1.3399e+06 75 -2.31 -0.044 -0.0883 -0.1252 33.266 33.258 1.3399e+06 -0.0198 -0.0671 -0.0922 -0.0744 -0.0258 -0.0276 0.4565 0.491 -0.0021 -0.1284 -0.2189 -0.211 -0.2242 33.158 -0.1078 1 51 57437 10.667 115 1.3399e+06 51.6 -2.3102 -0.0449 -0.0882 -0.1251 33.065 33.057 1.3399e+06 -0.0198 -0.0733 -0.0942 -0.0793 -0.0258 -0.0276 0.4563 0.4908 -0.0022 -0.1276 -0.2165 -0.2084 -0.2215 32.963 -0.1013 1 25 57436 -12.667 115.33 1.3404e+06 411.5 -2.3 -0.0015 -0.0826 -0.0829 11.533 11.519 1.3404e+06 -0.0198 -0.0614 -0.0903 -0.0699 -0.034 -0.0334 0.5984 0.5722 0.0026 -0.1212 -0.2298 -0.244 -0.2377 11.4 -0.1328 1 25 57436 -12.333 115.33 1.3404e+06 386.7 -2.3 -0.0023 -0.0848 -0.0838 12.438 12.421 1.3404e+06 -0.0198 -0.058 -0.0886 -0.0667 -0.0339 -0.0333 0.5998 0.5739 0.0025 -0.1208 -0.2329 -0.2457 -0.2429 12.312 -0.1266 1 25 57436 -12 115.33 1.3404e+06 347.3 -2.3001 -0.0034 -0.0866 -0.0851 12.967 12.957 1.3404e+06 -0.0198 -0.0586 -0.0901 -0.0672 -0.0337 -0.0332 0.6018 0.5764 0.0025 -0.1202 -0.2387 -0.247 -0.2442 12.897 -0.0703 1 25 57436 -11.667 115.33 1.3403e+06 324 -2.3002 -0.004 -0.0869 -0.0859 12.734 12.719 1.3403e+06 -0.0198 -0.0566 -0.0865 -0.0655 -0.0336 -0.0331 0.6027 0.5775 0.0024 -0.1199 -0.2425 -0.2474 -0.2414 12.67 -0.0642 1 216 57444 -7.6667 115.33 1.3404e+06 48.6 -2.3072 -0.0002 -0.0241 -0.0207 35.22 35.199 1.3404e+06 -0.0198 -0.0064 -0.0392 -0.02 0.0134 0.0132 -0.1069 -0.0604 0.0014 0.0574 -0.3976 -0.3615 -0.3628 35.241 0.0215 1 216 57444 -7.3333 115.33 1.3404e+06 34.7 -2.307 -0.0007 -0.0153 -0.0207 36.918 36.91 1.3404e+06 -0.0198 -0.0091 -0.0477 -0.0262 0.0121 0.012 -0.0958 -0.0706 0.0013 0.0585 -0.3925 -0.3684 -0.3694 36.91 -0.0076
.
  4 Comments

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 7 Sep 2022
According to Wikipedia the modified Julian date is the number of days since November 17, 1858. It is also the Julian date minus 2400000.5. Using one of the date and time entries from the data set:
D = datetime('2016-02-18 09:21:18.461')
D = datetime
18-Feb-2016 09:21:18
format longg
J = juliandate(D)
J =
2457436.889797
Using the subtraction method:
MJ1 = J - 2400000.5
MJ1 =
57436.3897970025
Using the epoch-based method:
MJ2 = days(D - datetime('November 17, 1858'))
MJ2 =
57436.3897970023
Those look to be in pretty good agreement. You could write a function to perform this conversion if you needed to use it in multiple places in your code (with a comment to explain the "magic day" of November 17, 1858.)
% See Variants table on https://en.wikipedia.org/wiki/Julian_day
modifiedJulianDate = @(DT) days(DT - datetime('November 17, 1858'));
modifiedJulianDate(D)
ans =
57436.3897970023
If you wanted the fractional year:
howManyYears = years(D - datetime('November 17, 1858'))
howManyYears =
157.255494081336
fractionalYear = rem(howManyYears, 1)
fractionalYear =
0.255494081335854
howManyDays = days(years(fractionalYear))
howManyDays =
93.3172970023107
That seems like about the right number of days from mid-November to mid-February.

Categories

Find more on Unit Conversions in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by