# Calculating the position of the Sun

I'm reading the book "Practical Astronomy with your Calculator or Spreadsheet 4th Edition" implementing its formulas with C++.

Now, I'm implementing formula 46 "Calculating the position of the Sun" and the first thing they do is define the epoch on which they shall base our calculations. They have chosen 2010 January 0.0 (JD = 2455196.5).

In the book there is an example asking: "what were the right ascension and declination of the Sun at 0hUT on Greenwich date 27 July 2003?"

In the second step to calculate that, they say:

Add 365 days for every year since 2010 plus 1 extra day for every leap year (see Table 2). The result is D. (Note that we subtract the total in this case as 2003 is before 2010.)

But I don't know, and this is my question, which years do I have to add? I have three options:

• 2010, 2009, 2008, 2007, 2006, 2005, 2004, 2003.
• 2010, 2009, 2008, 2007, 2006, 2005, 2004.
• 2009, 2008, 2007, 2006, 2005, 2004, 2003.

Which are the years that I have to add?

• Before you attempt to calculate the position of the Sun I would advise you to take a look at these planetary ephemerides, which include our mother star circumstances between 2011 and 2030. astropixels.com/ephemeris/ephemeris.html They are loose, but you can easily export them to MS Excel. Read the article below on how to do it: mkrgeo-blog.com/the-astropixels-com-ephemeris-data-extractor youtube.com/… or alternatively use the INDEX(IMPORTHTML) formula in Google Sheets youtube.com/watch?v=07Bm03b0Yhs&ab Commented Jun 25, 2021 at 8:30
• Do you want to know the future position of the sun wrt the stars at a fixed position of earth wrt to the sun? Commented Jun 25, 2021 at 18:56
• Why don't you use library functions to calculate the number of days since the epoch date? Eg, stackoverflow.com/a/31928010/4014959 Commented Jun 25, 2021 at 22:52

You shouldn't add 2010 because the date of interest is before 2010. None of the days in 2010 were in the time between 27 July 2003 and 0000 1 January 2010. Similarly, the time after 27 July 2003 until the end of the year isn't a complete year so you don't add it. That leaves you with the six whole years 2004 to 2009, 2 of them are leap years. 2192 days. The book's example should go on after that step to figuring the number of days 27 July to 31 December, inclusive.

• +1 can you double-check that I've done it that way in my answer? I'm not very confident. Thanks!
– uhoh
Commented Jun 26, 2021 at 6:58
• @uhoh I don't see a conflict. You do have a typo - two years 2006, but it's just a typo. Your year 2004, which should be the earliest full year, shows 6 years with 2 of them leap years, just like I said. Commented Jun 26, 2021 at 22:36
• Thanks, I'm prone to errors so I appreciate the confirmation.
– uhoh
Commented Jun 27, 2021 at 0:49

Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. For example, the years 1700, 1800, and 1900 are not leap years, but the years 1600 and 2000 are.

Following the instructions as you have quoted them which may or may not be correct:

Add 365 days for every year since 2010 plus 1 extra day for every leap year (see Table 2). The result is D. (Note that we subtract the total in this case as 2003 is before 2010.)

I get:

1996     -365*14 - 3        leap year
1997     -365*13 - 2
1998     -365*12 - 2
1999     -365*11 - 2
2000     -365*10 - 2        leap year (skip divisible by 100 but leap divisible by 400!)
2001     -365*9  - 2
2002     -365*8  - 2
2003     -365*7  - 2
2004     -365*6  - 2        leap year
2005     -365*5  - 1
2006     -365*4  - 1
2007     -365*3  - 1
2008     -365*2  - 1        leap year
2009     -365*1  - 0
2010     +0
2011     +365*1  + 0
2012     +365*2  + 1        leap year
2013     +365*3  + 1
2014     +365*4  + 1
2015     +365*5  + 1
2016     +365*6  + 2        leap year
2017     +365*7  + 2
2018     +365*8  + 2
2019     +365*9  + 2
2020     +365*10 + 3        leap year


I have to subtract these years:

• 2010, 2009, 2008, 2007, 2006, 2005, 2004

Because 2003 it isn't finished yet.

My problem was the word since because I don't understand it if I have to do it backward.