Monday – retrieving the date of the Monday for a specified week

Monday – retrieving the date of the Monday for a specified week

' Return the date of the Monday for a specified week..' This function can be tweaked to return any weekday. I use it in Access to' subdivide reports into weekly units, since Access displays only a number ' between 1 and 53 for the week when you group dates by week.'' Note: the Monday function requires the presence of the IsLeapYear function,' as well as the two arguments for the year and the week. Public Function Monday(intYear As Integer, intWeek As Integer) As Date    Static intMonday(53) As Date    Dim i As Long, x As Integer    Dim datDayNum As Date    Dim intNumDays As Integer    If IsLeapYear(intYear) Then        intNumDays = 365    Else        intNumDays = 364    End If    datDayNum = DateSerial(intYear, 1, 1)    If WeekDay(datDayNum) >= 3 And WeekDay(datDayNum) <= 6 Then        For i = datDayNum - 7 To datDayNum + intNumDays            If WeekDay(i) = 2 Then                x = x + 1                intMonday(x) = CDate(i)            End If        Next    Else        For i = datDayNum To datDayNum + intNumDays            If WeekDay(i) = 2 Then                x = x + 1                intMonday(x) = CDate(i)            End If        Next    End If    ' And finally:    Monday = intMonday(intWeek)End Function' This relatively simple function should work fine for any year between 100 and ' 9999,  using the Gregorian calendar.' As you can see, it tests the year for whether it is a multiple of 4, 100,'  or 400, using the Mod operator. It does not allow for years that VB can't ' handle.Public Function IsLeapYear(intYear As Integer) As Boolean    ' Multiples of 100 that are not also multiples of 400 are not leap years;    ' thus, 1900 was not, but 2000 was.    If intYear < 100 Or intYear > 9999 Then        MsgBox "The year provided must be between 100 and 9999, inclusive."        Exit Function    End If    If intYear Mod 400 = 0 Then        IsLeapYear = True    ElseIf intYear Mod 100 = 0 Then        IsLeapYear = False    ElseIf intYear Mod 4 = 0 Then        IsLeapYear = True    Else        IsLeapYear = False    End IfEnd Function

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing