0

I want to calculate difference between two dates, time and secs, and I know atleast for dates converting it to two Julian Numbers and subtracting it is an efficient way. I am trying to implement this algorithm for that. Below is my implementation for today i.e. 12-22-2015

function g(y,m,d)
m = (m + 9) % 12
y = y - m/10
return 365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + ( d - 1 )

function g(2015,12,22)
[9] m = (12 + 9) % 12
[2014.1] y = 2015 - 9/10

735146.5 + 503.525 + 20.141 + 5.03525 + 275.9 + 21
=**735954.10125**

However from this online calculation tool the correct value is: 2457378.877.

What am I doing wrong?

Maven
  • 14,587
  • 42
  • 113
  • 174

1 Answers1

0

Your fundamental problem is that the algorithm you use has a value of 1 around the start of 1AD. Julian dates start in 4713BC.

For your purposes that may not matter, (but it makes it harder to check online). Excel is good at comparing time points after the start of the 20th Century. If you actually want to convert to Julian date, you will need to search for the algorithm. For example: https://gist.github.com/jiffyclub/1294443 is suitable code in python - you will need to convert to your language of choice