Results 1 to 8 of 8

Thread: Calculating Day of Week Given MM-DD-YYYY

Threaded View

  1. #6

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Calculating Day of Week Given MM-DD-YYYY

    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:
    1. Private Function ConvertToDayOfWeek3( _
    2.         ByVal M As Long, _
    3.         ByVal D As Long, _
    4.         ByVal Y As Long _
    5.     ) As Long
    6.     Dim lReturn             As Long
    7.     Dim lYearStart          As Long
    8.     Dim lMonthOffset        As Long
    9.     Dim lDay                As Long
    10.     Dim lLeapYearAfterFeb   As Long
    11.    
    12.     lYearStart = Int(365.25 * (Y - 1))
    13.     lMonthOffset = Int(530526416330# / 10 ^ (M - 1)) - Int(530526416330# / 10 ^ M) * (10)
    14.     lLeapYearAfterFeb = (1 - Int((Y Mod 4) / (Y Mod 4 - 0.01))) * Int(Int(M / 3) / (Int(M / 3) - 0.0001))
    15.     lDay = D - 1
    16.    
    17.     lReturn = (lYearStart + lMonthOffset + lDay + lLeapYearAfterFeb) Mod 7
    18.    
    19.     ConvertToDayOfWeek3 = lReturn
    20. End Function
    Attached Images Attached Images  
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width