Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Everything Date
#2
Neat date routines.  Do you have a Get day of the Year function?  I have one that works (I think it works), but the code is kind of ugly.  Maybe there's a better way of doing this. 

- Dav

Code: (Select All)

Print "Today's date is: "; Date$
Print "Day of the year: "; DayOfTheYear

End


Function DayOfTheYear ()

    '2 bytes hold num of days for each month
    monthdays$ = "312831303130313130313031"

    'get current date values
    year = Val(Mid$(Date$, 7))
    month = Val(Mid$(Date$, 1, 2))
    day = Val(Mid$(Date$, 4, 2))

    'tally num of days in each month
    For d = 1 To month - 1 '(-1 is so we don't re-add the current month days)
        day = day + Val(Mid$(monthdays$, m + 1, 2)): m = m + 2
    Next

    'if it's a leap year, and after february, add one more day to total
    If month > 2 Then
        If (year Mod 4 = 0 And year Mod 100 <> 0) Or (year Mod 400 = 0) Then
            day = day + 1
        End If
    End If

    DayOfTheYear = day

End Function

Find my programs here in Dav's QB64 Corner
Reply


Messages In This Thread
Everything Date - by SMcNeill - 10-16-2023, 04:41 AM
RE: Everything Date - by Dav - 09-17-2024, 01:58 PM
RE: Everything Date - by SMcNeill - 09-17-2024, 03:07 PM
RE: Everything Date - by Dav - 09-19-2024, 10:50 AM



Users browsing this thread: 2 Guest(s)