Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use fromJulianDate() properly?

How to use fromJulianDate() properly?

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 7 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manikanta27
    wrote on last edited by manikanta27
    #1

    My Julain number is 20255 and output I expect is11-sep-2020 as per this page: http://www.longpelaexpertise.com/toolsJulian.php
    But my output is as per this page: https://core2.gsfc.nasa.gov/time/julian.html
    I want the output to be as per first link when I call fromJulianDay in QDate. What needs to be fixed here? Thanks in advance.

    QDate regdate = QDate::fromJulianDay(20255)
    
    S 1 Reply Last reply
    0
    • M manikanta27

      My Julain number is 20255 and output I expect is11-sep-2020 as per this page: http://www.longpelaexpertise.com/toolsJulian.php
      But my output is as per this page: https://core2.gsfc.nasa.gov/time/julian.html
      I want the output to be as per first link when I call fromJulianDay in QDate. What needs to be fixed here? Thanks in advance.

      QDate regdate = QDate::fromJulianDay(20255)
      
      S Offline
      S Offline
      SimonSchroeder
      wrote on last edited by
      #13

      @manikanta27 said in How to use fromJulianDate() properly?:

      My Julain number is 20255 and output I expect is11-sep-2020

      I don't know about Julian number, dates, etc. However, what I see in your original question is more like: 20255 means the 255th day of 2020. Is that just a coincidence? Or is it always that the first two digits denote the year and the remaining digits the day of the year? The first link suggests that this is what you actually mean. Having a two digit year unfortunately means that you have to decide on the century somehow.

      If I am right, than this is what you want:

      QString julianStr = "20255";
      QDate date = QDate(julianStr.left(2).toInt()+2000, 1, 1).addDays(julianStr.right(3).toInt() - 1);
      
      M 1 Reply Last reply
      4
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @manikanta27 said in How to use fromJulianDate() properly?:

        My Julain number is 20255 and output I expect is11-sep-2020

        It's not really correct - your day number is a 'Truncated JulianDay' as described in wikipedia.. QDate only accepts full julian dates. Adjust your value accordingly.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        JonBJ 1 Reply Last reply
        4
        • Christian EhrlicherC Christian Ehrlicher

          @manikanta27 said in How to use fromJulianDate() properly?:

          My Julain number is 20255 and output I expect is11-sep-2020

          It's not really correct - your day number is a 'Truncated JulianDay' as described in wikipedia.. QDate only accepts full julian dates. Adjust your value accordingly.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #3

          @Christian-Ehrlicher
          What an excellent answer! Is there anything obscure like this that you don't know? :)

          Purely OOI, who has any use for Julian dates referring to dates nowadays (as opposed to in Roman times)??

          Christian EhrlicherC 1 Reply Last reply
          0
          • JonBJ JonB

            @Christian-Ehrlicher
            What an excellent answer! Is there anything obscure like this that you don't know? :)

            Purely OOI, who has any use for Julian dates referring to dates nowadays (as opposed to in Roman times)??

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @JonB said in How to use fromJulianDate() properly?:

            Is there anything obscure like this that you don't know? :)

            a lot :)

            When you're interested in more formats look e.g. for DTG.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            M 1 Reply Last reply
            2
            • M Offline
              M Offline
              manikanta27
              wrote on last edited by
              #5

              @Christian-Ehrlicher
              thanks for the lead. So the formula was

              TJD = floor (JD − 2440000.5)
              

              Can you help me with the math so that I could get JD from that equation?

              KroMignonK 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @JonB said in How to use fromJulianDate() properly?:

                Is there anything obscure like this that you don't know? :)

                a lot :)

                When you're interested in more formats look e.g. for DTG.

                M Offline
                M Offline
                manikanta27
                wrote on last edited by manikanta27
                #6

                @Christian-Ehrlicher
                can you reply to my last post?

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #7

                  Bro... it's just an addition.... +2440000

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  2
                  • M manikanta27

                    @Christian-Ehrlicher
                    thanks for the lead. So the formula was

                    TJD = floor (JD − 2440000.5)
                    

                    Can you help me with the math so that I could get JD from that equation?

                    KroMignonK Offline
                    KroMignonK Offline
                    KroMignon
                    wrote on last edited by
                    #8

                    @manikanta27 said in How to use fromJulianDate() properly?:

                    TJD = floor (JD − 2440000.5)

                    Can you help me with the math so that I could get JD from that equation?

                    Did you take time to understand this?
                    floor() is java function (https://www.tutorialspoint.com/java/number_floor.htm) to get the upper round value.

                    If you have learn a bit of mathematics, I think you can resolve this TJD = JD - 244000 ==> JD = ....

                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                    M jeremy_kJ 2 Replies Last reply
                    0
                    • KroMignonK KroMignon

                      @manikanta27 said in How to use fromJulianDate() properly?:

                      TJD = floor (JD − 2440000.5)

                      Can you help me with the math so that I could get JD from that equation?

                      Did you take time to understand this?
                      floor() is java function (https://www.tutorialspoint.com/java/number_floor.htm) to get the upper round value.

                      If you have learn a bit of mathematics, I think you can resolve this TJD = JD - 244000 ==> JD = ....

                      M Offline
                      M Offline
                      manikanta27
                      wrote on last edited by
                      #9

                      @KroMignon @VRonin Hey math experts.
                      I did that already. I asked for calculation because the final number is not what I expect.
                      If I feed 2459104 to fromJulianDate(), then my output is 11Sep2020 (requirement fulfilled).
                      My TJD is 20255, adding 2440000 gives 2460255, for which output is 6Nov2023 (thumbs down).
                      The difference between 2460255 & 2459104 is a lot, 1151.
                      So, the formula is wrong.

                      KroMignonK 2 Replies Last reply
                      0
                      • M manikanta27

                        @KroMignon @VRonin Hey math experts.
                        I did that already. I asked for calculation because the final number is not what I expect.
                        If I feed 2459104 to fromJulianDate(), then my output is 11Sep2020 (requirement fulfilled).
                        My TJD is 20255, adding 2440000 gives 2460255, for which output is 6Nov2023 (thumbs down).
                        The difference between 2460255 & 2459104 is a lot, 1151.
                        So, the formula is wrong.

                        KroMignonK Offline
                        KroMignonK Offline
                        KroMignon
                        wrote on last edited by
                        #10

                        @manikanta27 said in How to use fromJulianDate() properly?:

                        So, the formula is wrong.

                        Maybe, but this was not the question...

                        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                        M 1 Reply Last reply
                        0
                        • M manikanta27

                          @KroMignon @VRonin Hey math experts.
                          I did that already. I asked for calculation because the final number is not what I expect.
                          If I feed 2459104 to fromJulianDate(), then my output is 11Sep2020 (requirement fulfilled).
                          My TJD is 20255, adding 2440000 gives 2460255, for which output is 6Nov2023 (thumbs down).
                          The difference between 2460255 & 2459104 is a lot, 1151.
                          So, the formula is wrong.

                          KroMignonK Offline
                          KroMignonK Offline
                          KroMignon
                          wrote on last edited by
                          #11

                          @manikanta27 said in How to use fromJulianDate() properly?:

                          If I feed 2459104 to fromJulianDate(), then my output is 11Sep2020 (requirement fulfilled).
                          My TJD is 20255, adding 2440000 gives 2460255, for which output is 6Nov2023 (thumbs down).
                          The difference between 2460255 & 2459104 is a lot, 1151.
                          So, the formula is wrong.

                          Are you sure about the value you are using?

                          • Are you using Modified Julian Day (origin time is 17.11.1858)? ==> MJD = JD - 2400000.5
                          • Are you using Truncate Julian Day (origin time is 24.05.1968, first Apollo mission)? ==> TJD = JD - 2440000.5 = MJD + 40000

                          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                          M 1 Reply Last reply
                          0
                          • KroMignonK KroMignon

                            @manikanta27 said in How to use fromJulianDate() properly?:

                            So, the formula is wrong.

                            Maybe, but this was not the question...

                            M Offline
                            M Offline
                            manikanta27
                            wrote on last edited by
                            #12

                            @KroMignon yes that was not the question but the answer was. I guess we are just continuing the thread based on the question and the first answer.

                            KroMignonK 1 Reply Last reply
                            0
                            • M manikanta27

                              My Julain number is 20255 and output I expect is11-sep-2020 as per this page: http://www.longpelaexpertise.com/toolsJulian.php
                              But my output is as per this page: https://core2.gsfc.nasa.gov/time/julian.html
                              I want the output to be as per first link when I call fromJulianDay in QDate. What needs to be fixed here? Thanks in advance.

                              QDate regdate = QDate::fromJulianDay(20255)
                              
                              S Offline
                              S Offline
                              SimonSchroeder
                              wrote on last edited by
                              #13

                              @manikanta27 said in How to use fromJulianDate() properly?:

                              My Julain number is 20255 and output I expect is11-sep-2020

                              I don't know about Julian number, dates, etc. However, what I see in your original question is more like: 20255 means the 255th day of 2020. Is that just a coincidence? Or is it always that the first two digits denote the year and the remaining digits the day of the year? The first link suggests that this is what you actually mean. Having a two digit year unfortunately means that you have to decide on the century somehow.

                              If I am right, than this is what you want:

                              QString julianStr = "20255";
                              QDate date = QDate(julianStr.left(2).toInt()+2000, 1, 1).addDays(julianStr.right(3).toInt() - 1);
                              
                              M 1 Reply Last reply
                              4
                              • KroMignonK KroMignon

                                @manikanta27 said in How to use fromJulianDate() properly?:

                                If I feed 2459104 to fromJulianDate(), then my output is 11Sep2020 (requirement fulfilled).
                                My TJD is 20255, adding 2440000 gives 2460255, for which output is 6Nov2023 (thumbs down).
                                The difference between 2460255 & 2459104 is a lot, 1151.
                                So, the formula is wrong.

                                Are you sure about the value you are using?

                                • Are you using Modified Julian Day (origin time is 17.11.1858)? ==> MJD = JD - 2400000.5
                                • Are you using Truncate Julian Day (origin time is 24.05.1968, first Apollo mission)? ==> TJD = JD - 2440000.5 = MJD + 40000
                                M Offline
                                M Offline
                                manikanta27
                                wrote on last edited by
                                #14

                                @KroMignon It surely is a truncated one.
                                I initially started off with MJD but the difference is way more than expected between actual and expected (more than I got from TJD formula).
                                Anyway, for time's sake, I went with an alternate method. For my application I only need month number and year from TJD (20255) and not the exact date. I took leap years into consideration and wrote a routine to extract month number from day number (255 here). That should do fine for period 2000-2099.

                                Thank you for the support.

                                1 Reply Last reply
                                0
                                • M manikanta27

                                  @KroMignon yes that was not the question but the answer was. I guess we are just continuing the thread based on the question and the first answer.

                                  KroMignonK Offline
                                  KroMignonK Offline
                                  KroMignon
                                  wrote on last edited by KroMignon
                                  #15

                                  @manikanta27 said in How to use fromJulianDate() properly?:

                                  yes that was not the question but the answer was. I guess we are just continuing the thread based on the question and the first answer.

                                  Have you take time to read the date reference used by the tool are using?

                                  We refer to a yyddd date format (yy = year, ddd=day) as a 'Julian Date'
                                  A yyddd (or similar format such as yyyyddd, yy-ddd) date is more correctly called an ordinal date. However in the mainframe world, we call them 'Julian Dates', and so we've used this term on this page.

                                  So in your example: 20255 means 255 day of 2020!

                                  To convert to QDate:

                                  QString oDate="20255";
                                  QDate regdate = QDate(2000 + oDate.left(2).toInt(), 1, 1).addDay(oDate.right(3).toInt()-1);
                                  

                                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                  M 1 Reply Last reply
                                  4
                                  • KroMignonK KroMignon

                                    @manikanta27 said in How to use fromJulianDate() properly?:

                                    yes that was not the question but the answer was. I guess we are just continuing the thread based on the question and the first answer.

                                    Have you take time to read the date reference used by the tool are using?

                                    We refer to a yyddd date format (yy = year, ddd=day) as a 'Julian Date'
                                    A yyddd (or similar format such as yyyyddd, yy-ddd) date is more correctly called an ordinal date. However in the mainframe world, we call them 'Julian Dates', and so we've used this term on this page.

                                    So in your example: 20255 means 255 day of 2020!

                                    To convert to QDate:

                                    QString oDate="20255";
                                    QDate regdate = QDate(2000 + oDate.left(2).toInt(), 1, 1).addDay(oDate.right(3).toInt()-1);
                                    
                                    M Offline
                                    M Offline
                                    manikanta27
                                    wrote on last edited by
                                    #16

                                    @KroMignon Thanks. @SimonSchroeder posted the same and it worked. I found an excel formula coincidentally which has exactly the same calculation.

                                    KroMignonK 1 Reply Last reply
                                    0
                                    • M manikanta27

                                      @KroMignon Thanks. @SimonSchroeder posted the same and it worked. I found an excel formula coincidentally which has exactly the same calculation.

                                      KroMignonK Offline
                                      KroMignonK Offline
                                      KroMignon
                                      wrote on last edited by KroMignon
                                      #17

                                      @manikanta27 said in How to use fromJulianDate() properly?:

                                      Thanks. @SimonSchroeder posted the same and it worked. I found an excel formula coincidentally which has exactly the same calculation.

                                      You're welcome, but I would suggest you, next time, to carefully read the tools you are using.
                                      The coding of the number is clearly done on the web page you used to convert it.
                                      I hope you have noted, it is not a Julian Day/Date but an Ordinal Date (cf. https://en.wikipedia.org/wiki/Ordinal_date).

                                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                      M 1 Reply Last reply
                                      2
                                      • S SimonSchroeder

                                        @manikanta27 said in How to use fromJulianDate() properly?:

                                        My Julain number is 20255 and output I expect is11-sep-2020

                                        I don't know about Julian number, dates, etc. However, what I see in your original question is more like: 20255 means the 255th day of 2020. Is that just a coincidence? Or is it always that the first two digits denote the year and the remaining digits the day of the year? The first link suggests that this is what you actually mean. Having a two digit year unfortunately means that you have to decide on the century somehow.

                                        If I am right, than this is what you want:

                                        QString julianStr = "20255";
                                        QDate date = QDate(julianStr.left(2).toInt()+2000, 1, 1).addDays(julianStr.right(3).toInt() - 1);
                                        
                                        M Offline
                                        M Offline
                                        manikanta27
                                        wrote on last edited by
                                        #18

                                        @SimonSchroeder Firstly, thank you for understanding the question. You read my mind. I never knew that there are so many date formats existing. Wish you had seen the question first before anyone else did. Anyway I got enlightened with some knowledge because of other guys.

                                        1 Reply Last reply
                                        0
                                        • KroMignonK KroMignon

                                          @manikanta27 said in How to use fromJulianDate() properly?:

                                          Thanks. @SimonSchroeder posted the same and it worked. I found an excel formula coincidentally which has exactly the same calculation.

                                          You're welcome, but I would suggest you, next time, to carefully read the tools you are using.
                                          The coding of the number is clearly done on the web page you used to convert it.
                                          I hope you have noted, it is not a Julian Day/Date but an Ordinal Date (cf. https://en.wikipedia.org/wiki/Ordinal_date).

                                          M Offline
                                          M Offline
                                          manikanta27
                                          wrote on last edited by
                                          #19

                                          @KroMignon Sure man. Not just next time. Always.
                                          Right, it is an Ordinal date not Julian.

                                          1 Reply Last reply
                                          0
                                          • KroMignonK KroMignon

                                            @manikanta27 said in How to use fromJulianDate() properly?:

                                            TJD = floor (JD − 2440000.5)

                                            Can you help me with the math so that I could get JD from that equation?

                                            Did you take time to understand this?
                                            floor() is java function (https://www.tutorialspoint.com/java/number_floor.htm) to get the upper round value.

                                            If you have learn a bit of mathematics, I think you can resolve this TJD = JD - 244000 ==> JD = ....

                                            jeremy_kJ Offline
                                            jeremy_kJ Offline
                                            jeremy_k
                                            wrote on last edited by
                                            #20

                                            @KroMignon said in How to use fromJulianDate() properly?:

                                            floor() is java function (https://www.tutorialspoint.com/java/number_floor.htm) to get the upper round value.

                                            floor() also exists and does the same thing in C, python, ecmascript, and likely every computer language used for numerical computation.

                                            Upper round sounds more like ceil().

                                            floor(3) - round to largest integral value not greater than x
                                            ceil(3) - round to smallest integral value not less than x

                                            Asking a question about code? http://eel.is/iso-c++/testcase/

                                            1 Reply Last reply
                                            0

                                            • Login

                                            • Login or register to search.
                                            • First post
                                              Last post
                                            0
                                            • Categories
                                            • Recent
                                            • Tags
                                            • Popular
                                            • Users
                                            • Groups
                                            • Search
                                            • Get Qt Extensions
                                            • Unsolved