VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Calendar Function useful in finding a particular day of the week in any month.

by Steve Carpenter (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Tue 19th February 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Calendar Function useful in finding a particular day of the week in any month.

Rate Calendar Function useful in finding a particular day of the week in any month.



'Standard Code Module for Calendar Functions
'Programmers Name: Steve Carpenter
'E-Mail: [email protected]
'File Name: Calendar_Functions.bas
'Date created: February 10, 2002
'Last Modified: February 15, 2002
'Function Names:  GetDayOfWeek()
' IsLeapYear()
' DaysInMonth()
'
'This Module contains functions to;
' 1.)Find what day of the week a particular day is
' 2.)Determine if it is leap year or not
' 3.)Determine the number of days in a month (even in a leap year)
'
'In each of the functions in this module type for year will allways be LONG
'type for month and day will be of INTEGER type
*
'

'
'
*
Public Function GetDayOfWeek(MyYear as Long, MyMonth as Integer, MyDay as Integer) as Integer
'************************************************************
'GetDayOfWeek() Function used to find what day of the week a certain date is
'The algorhythm for finding the day is basically borrowed from the Linux CAL command
'source code with some modifications for Visual Basic
'This function is passed 2 variables of Integer type and 1 of long type
'Year, Month, Day
'This function returns 1 variable "GetDayOfWeek" of Integer type
'all division in this function are of INTEGER type
'this function will return an integer value of 0 to 6
'0 is sunday, 1 is monday, 2 is tuesday...
'this function does handle leap year
'************************************************************

Dim Var1 as Integer

'var1 will allways be 0 or 1
Var1 = Int((14 - MyMonth) / 12)

'subtract either 0 or 1 from the year
MyYear = MyYear - Var1

'remember order of operations if you are doing this by hand
MyMonth = MyMonth + 12 * Var1 - 2

'if you wanted to find the first day of the month, you would make
'MyDay = 1 in the calling procedure.

GetDayOfWeek = (MyDay + MyYear + Int(MyYear / 4) - Int(MyYear / 100) + _
    Int(MyYear / 400) + Int((31 * MyMonth) / 12)) Mod 7
 
'getdayofweek will now contain the value of 0 to 6

End Function

'
'
'
'
'

Public Function IsLeapYear(MyYear as Long) as Boolean

'************************************************************
'IsLeapYear() Function used to find if a particular year is leap year 
'or not. This function is passed 1 long variable
'returns IsLeapYear--a boolean
'************************************************************

    IsLeapYear = MyYear Mod 4 = 0 And (MyYear Mod 100 <> 0 Or MyYear Mod 400 = 0)
           
End Function

'
'
'
'

Public Function GetDaysInMonth(MyMonth as Integer, MyYear as Long) as Integer
'************************************************************
'GetDaysInMonth() function used to find how many days are in
' a particular month
'this function receives 2 integer variable Month and 
'Year and returns the numbers of days in the month "DaysInMonth"
'if the intMonth = 2, which is February, then it uses the 
'IsLeapYear() function to find out if it is leap year
'If it is leap year, February will have 29 days
'************************************************************

Select Case intMonth
Case 2
If IsLeapYear(MyYear) then
GetDaysInMonth = 29
Else
GetDaysInMonth = 28
Case 4,6,9,11
GetDaysInMonth = 30
Case 1, 3, 5, 7, 8, 10, 12
GetDaysInMonth = 31
End Select
End Function



Download this snippet    Add to My Saved Code

Calendar Function useful in finding a particular day of the week in any month. Comments

No comments have been posted about Calendar Function useful in finding a particular day of the week in any month.. Why not be the first to post a comment about Calendar Function useful in finding a particular day of the week in any month..

Post your comment

Subject:
Message:
0/1000 characters