I know there are probably ways to do this already, but I came up with this one all by myself.
Printable View
I know there are probably ways to do this already, but I came up with this one all by myself.
Sounds like you want the Julian Date. Check this out.
I know there are other ways out there. My intention when doing this was to come up with my own formula. I didn't want to look anywhere online otherwise I wouldn't be able to figure it out by self because I would have that info in the back of my head, influencing my thought process.
After I simplify the formula above as much as possible, I will look up Julian Dates online.
Quote:
Originally Posted by eyeRmonkey
Oh I see. I am indeed very much impressed with that formula! :thumb: I no longer have the inspiration to sit and come up with stuff like that anymore :bigyello:
I'm glad you like it. It only took me a few hours of actual thought (maybe 5?). There is a lot of binary (true/false) logic to it because I am too used to programming. Its really ugly and I am trying to simplify it.
Here it is in VB is anyone cares:
VB Code:
Private Function Convert( _ ByVal M As Long, _ ByVal D As Long, _ ByVal Y As Long _ ) Dim lReturn As Long Dim lYearStart As Long Dim lMonthStart As Long Dim lMonthOffset As Long Dim lDay As Long lYearStart = Int((Y - 1) * (365.25)) lMonthStart = (M - 1) * 30 lMonthOffset = (1) * Int(Int(M / 2) / (Int(M / 2) - 0.0001)) + _ (-2 + (1 - Int((Y Mod 4) / ((Y Mod 4) - 0.0001)))) * Int(Int(M / 3) / (Int(M / 3) - 0.0001)) + _ (1) * Int(Int(M / 4) / (Int(M / 4) - 0.0001)) + _ (1) * Int(Int(M / 6) / (Int(M / 6) - 0.0001)) + _ (1) * Int(Int(M / 8) / (Int(M / 8) - 0.0001)) + _ (1) * Int(Int(M / 9) / (Int(M / 9) - 0.0001)) + _ (1) * Int(Int(M / 11) / (Int(M / 11) - 0.0001)) lDay = D - 1 lReturn = (lYearStart + lMonthStart + lMonthOffset + lDay) Mod 7 Convert = lReturn End Function
Okay, I have spent a lot of time simplifying this formula. I attached an image of the new version. This is actually the 3rd revision I have made. The last one I didn't post because it was only slightly nicer than the one above.
Here is the code in VB.
VB Code:
Private Function ConvertToDayOfWeek3( _ ByVal M As Long, _ ByVal D As Long, _ ByVal Y As Long _ ) As Long Dim lReturn As Long Dim lYearStart As Long Dim lMonthOffset As Long Dim lDay As Long Dim lLeapYearAfterFeb As Long lYearStart = Int(365.25 * (Y - 1)) lMonthOffset = Int(530526416330# / 10 ^ (M - 1)) - Int(530526416330# / 10 ^ M) * (10) lLeapYearAfterFeb = (1 - Int((Y Mod 4) / (Y Mod 4 - 0.01))) * Int(Int(M / 3) / (Int(M / 3) - 0.0001)) lDay = D - 1 lReturn = (lYearStart + lMonthOffset + lDay + lLeapYearAfterFeb) Mod 7 ConvertToDayOfWeek3 = lReturn End Function
Check this one out, at least you'll have an on-line benchmark to test your code against.
Compare it to the formula shown in this thread...
http://www.vbforums.com/showthread.p...ht=1582+julian
One is mainframe BASIC, the other is VB - but basically the same formula...