Extended Timer and TimeStamp
#2
@SMcNeill ,
You can replace 13 lines of code with 2 lines (see code).  And running the code will show it works.
EDIT: .. with 1 line of code .. (code was changed)

Re "What Happened?":  
  I don't see how you can get so much done in one day!  
  But thanks!

Code: (Select All)
Option _Explicit
DefLng A-Z
Dim d, m, t
If 0 Then

  ' ---- you can replace the following: ----
  Select Case m 'Add the number of days for each previous month passed
    Case 2: d = d + 31
    Case 3: d = d + 59
    Case 4: d = d + 90
    Case 5: d = d + 120
    Case 6: d = d + 151
    Case 7: d = d + 181
    Case 8: d = d + 212
    Case 9: d = d + 243
    Case 10: d = d + 273
    Case 11: d = d + 304
    Case 12: d = d + 334
  End Select

  ' ---- with the following: ----
  d = d + Int((295 + 153 * ((m + 9) Mod 12) + 2) / 5) Mod 365

End If

' -- proof:
Print "Date", "Method1", "Method2", "Difference"
For m = 1 To 12
  Print Str$(m) + "/1", Method1(m, 1), Method2(m, 1), Method1(m, 1) - Method2(m, 1)
Next m
Print "Dec 31", Method1(12, 31), Method2(12, 31), Method1(12, 31) - Method2(12, 31)

Function Method1 (m, d)
  Select Case m 'Add the number of days for each previous month passed
    Case 2: d = d + 31
    Case 3: d = d + 59
    Case 4: d = d + 90
    Case 5: d = d + 120
    Case 6: d = d + 151
    Case 7: d = d + 181
    Case 8: d = d + 212
    Case 9: d = d + 243
    Case 10: d = d + 273
    Case 11: d = d + 304
    Case 12: d = d + 334
  End Select
  Method1 = d
End Function

Function Method2 (m, d)
  Method2 = d + Int((295 + 153 * ((m + 9) Mod 12) + 2) / 5) Mod 365
End Function
Reply


Messages In This Thread
Extended Timer and TimeStamp - by SMcNeill - 04-20-2022, 02:17 AM
RE: Extended Timer and TimeStamp - by dcromley - 04-22-2022, 07:30 PM
RE: Extended Timer and TimeStamp - by SMcNeill - 01-02-2023, 05:37 AM
RE: Extended Timer and TimeStamp - by SMcNeill - 01-02-2023, 01:30 PM



Users browsing this thread: 2 Guest(s)