29.12.2014, 14:43
Julian Day
I was recently given a java project from school. it was a bank type software it had many types of account. In one type i needed to calculate interest according to days from last login, tried for hours to take out difference between days with help of dates but couldn't take out so after googling I came across Julian Day which solved my problem. So i thought that I should share this thing with you guys.Introduction
Julian day is the continuous count of days since the beginning of the Julian Period[November 24, 4714 BC] used primarily by astronomers.
The Julian Day Number (JDN) is the integer assigned to a whole solar day in the Julian day count starting from noon Greenwich Mean Time, with........
Read more here
Functions for it
So here are the functions in PAWN to get Julian Day value from a date and vice-versa.
pawn Code:
stock DateToJulian(year, month, day)
{
new a = (14 - month) / 12;
new y = year + 4800 - a;
new m = month + 12 * a - 3;
new jdn = day + (153 * m + 2)/5 + 365*y + y/4 - y/100 + y/400 - 32045;
return jdn;
}
pawn Code:
stock JulianToDate(jdn, &year, &month, &day)
{
jdn -= 1721119;
year = (400 * jdn) / 146097;
while (365*year + year/4 - year/100 + year/400 < jdn)
year++;
year--;
jdn -= 365*year + year/4 - year/100 + year/400;
month = (5*jdn + 457) / 153;
day = jdn - (153*month - 457) / 5;
if (month > 12)
month -= 12, year++;
if (year <= 0)
year--;
}
Eamples
So these examples are using above functions
pawn Code:
main()
{
new julian = DateToJulian(2014, 12, 29);
printf("2014/12/19 Julian Day: %i", julian);
new d,m,y;
JulianToDate(julian, y, m, d);
printf("Its date converted again : %i/%i/%i",y,m,d);
}
Quote:
Output: 2014/12/29 Julian Day: 2457021 Its date converted again : 2014/12/29 |
pawn Code:
new diffrence = DateToJulian(y1, m1, d1) - DateToJulian(y2, m2, d2);
Possible uses
-Temporary ban/vip system based on days only.
Can't think of anything else but I am pretty sure you guys could