Sunday, October 3, 2010

Visual Basic Date and Time Function : Weekday , Month , Day , Year

Purpose : The Weekday , Month , Day and Year function return an integer value representing the day of the week , the month , the day , or the year , respectively . These values can be used to construct or format a bate in usual terms , such as Thursday, December 15, 1997

Syntax :
Month ( expression$ )
Day ( expression$ )
Year ( expression$ )
Weekday ( expression$ , [ firstdayof week ] )

expression$ : Date variant to display in month, day , year or weekday format
firstdayofweek : Aconstant that specifies the first day of the week . omitted , vbsunday is assumed.


Private Sub Form_Load()
Dim CMonth%, CDay%, CYear%, CWeek%
Dim Yr$, M$, W$
CMonth% = Month(Now)
CDay% = Day(Now)
CYear% = Year(Now)
CWeek% = Weekday(Now)
If CYear% "Less Then" 2000 Or CYear > 1899 Then
Yr$ = Format(CYear%, "yy")
Else
Yr$ = Str$(CYear%)
End If
Select Case CMonth%
Case 1: M$ = "Q1 January "
Case 2: M$ = "Q1 Febuary "
Case 3: M$ = "Q1 March "
Case 4: M$ = "Q2 April "
Case 5: M$ = "Q2 May "
Case 6: M$ = "Q2 June "
Case 7: M$ = "Q3 July "
Case 8: M$ = "Q3 August "
Case 9: M$ = "Q3 September "
Case 10: M$ = "Q4 October "
Case 11: M$ = "Q4 November "
Case 12: M$ = "Q4 December "
End Select
Select Case CWeek%
Case vbSunday: W$ = "Sunday "
Case vbMonday: W$ = "Monday "
Case vbTuesday: W$ = "Tuesday "
Case vbWednesday: W$ = "Wednesday "
Case vbThursday: W$ = "Thursday "
Case vbFriday: W$ = "Friday "
Case vbSaturday : W$ = "Saturday "
End Select
Text1.Text = W$ & " , " & M$ & Str(CDay%) & " , " & Str$(CYear%)
End Sub

Note : Less Then use sing

No comments:

Post a Comment