Calculate week number in a period of years like JDN in js

277 Views Asked by At

I understand that i can get a number that represent the day number in a julian calendar. JDN http://en.wikipedia.org/wiki/Julian_day. For example for a date 10/10/10 i can get a number 2455479.5. My question is how to get a weeks and moths number, that means a continuous number of months or weeks like the JDN. This si very useful in reports and BI dashboards. I am using js but it can be useful for other languages.

1

There are 1 best solutions below

0
On

The Julian Day provides a universally accepted day count from a specific point in time -- but there is no universally accepted week or month count that is comparable with the Julian Day count.

The closest thing to an official week count is the ISO 8601 standard, but it recycles every year, so it's quite different from what you're suggesting.

You could certainly extrapolate the week count from the Julian Day, simply dividing by 7. And you could come up with a month count with some basic math. I haven't tested this, but off the top of my head, I think it would be ((current year - -4713) * 12) + 2 + number of month in this year). (The "+ 2" is to adjust for the fact that the Julian Day count started in November, so we're adding 1 for November and 1 for December of that year. This also uses astronomical calculation [which has a Year 0] rather than historical calculation [which jumps from 1 BCE to 1 CE]; if you're using the historical calculation, adjust accordingly.)

In short, though, if you're looking to implement something that already exists and that will be recognizable to others, I think you'll find there's nothing out there.