How to use fromJulianDate() properly?
-
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)
-
@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);
-
@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.
-
@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)??
-
@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.
-
@Christian-Ehrlicher
thanks for the lead. So the formula wasTJD = floor (JD − 2440000.5)
Can you help me with the math so that I could get JD from that equation?
-
@Christian-Ehrlicher
can you reply to my last post? -
@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 = ....
-
@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. -
@manikanta27 said in How to use fromJulianDate() properly?:
So, the formula is wrong.
Maybe, but this was not the question...
-
@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
-
@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.
-
@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);
-
@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.
-
@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);
-
@KroMignon Thanks. @SimonSchroeder posted the same and it worked. I found an excel formula coincidentally which has exactly the same calculation.
-
@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). -
@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.
-
@KroMignon Sure man. Not just next time. Always.
Right, it is an Ordinal date not Julian. -
@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