Determine Monday

In VB, the (Saturday Mod 7) = 0.

' VBA Example: Determine Monday
Public Function Monday(a_dt As Date) As Date
    Dim t As Long
    
    t = Int(a_dt)
    Monday = t - ((t + 6) Mod 7) + 1
End Function

 

' VBA Example: Determine Monday
' version 2
Public Function Monday(a_dt As Date) As Date
    Dim t As Long
    
    t = Int(a_dt) - 1
    Monday = t - (t Mod 7) + 2
End Function

 

' VBScript: determine the first monday of the month of a given date
Public Function First_Monday(a_dt) 
    Dim t

    t = Int(a_dt) - Day(a_dt) + 7
    First_Monday =  t - ((t + 6) Mod 7) + 1
End Function
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s