Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning the day of a week

Status
Not open for further replies.

magezi

Programmer
Mar 2, 2000
118
0
0
UG
I want a function that would return the day of a week
eg if mydate is a date and fn() is the function I want the result of fn(mydate) to be say "Monday" . I nkow day()returns the day bu in numerical values. Nkabirwa Sowed Magezi
nkabirwa@yahoo.com

A Ugandan Developer for

(1) School Management Information System(SMIS) - Foxpro 2.6 ; Ms-Acess 97

(2)Debt onitoring System(DMS) - Ms-Acess 97

(3) The Loans Recovery System(LS) - Ms- Access 97

(4) The Dry Cleaners System(DS) - Ms- Access 97
 
on of many ways

?format(date(),"dddd")
Tuesday
 
Try the following function:

Code:
Function fn()

Dim mydate As Date

mydate = Date 'Returns current date

    Select Case WeekDay(mydate) 'Returns the weekday number of mydate variable
        Case 1
            fn = "Sunday"
        Case 2
            fn = "Monday"
        Case 3
            fn = "Tuesday"
        Case 4
            fn = "Wednesday"
        Case 5
            fn = "Thursday"
        Case 6
            fn = "Friday"
        Case 7
            fn = "Saturday"
    End Select

End Function

This uses the Weekday function to return a numerical value for the variable. Then it uses the Case Select command to return the day.

HTH

cew657
 
Private Sub Command0_Click()
MsgBox fDayofWeek(Text1.Value)
End Sub

Function fDayofWeek(myDate As Date)
Select Case Format(myDate, "ddd")
Case "Sun"
fDayofWeek = "Sunday"
Case "Mon"
fDayofWeek = "Monday"
Case "Tue"
fDayofWeek = "Tuesday"
Case "Wed"
fDayofWeek = "Wednesday"
Case "Thu"
fDayofWeek = "Thursday"
Case "Fri"
fDayofWeek = "Friday"
Case "Sat"
fDayofWeek = "Saturday"
Case Else
'Error
End Select
End Function
 
When does the date() function work ? I have Ms-Access on a windows 2000 machine and windows 98.
I was shocked to call the date() function from a report from the win 98 machines and it nothing was returned when I run the same report on win 2000 machine it gave the correct date for that day Some one help when does this function work ?
 
Usually when the date function fails to work in access it is due to a refrence problem. See the FAQ it describes in detail what to do I think it is uder common function fail to work or something like that.
 
Dim MyDate
Set Mydate = Day(Date)

If MyDate = 1 then
Set Mydate = Monday
Elseif Mydate = 2 Then
Set Mydate = Tuesday
...etc...

End If

This should work.

-Josh ------------------
-JPeters
Got a helpful tip for Access Users? Check out and contribute to 'How to Keep Your Databases from becoming Overwhelming!'
thread181-293590
jpeters@guidemail.com
------------------
 
CORRECTION - forgot my quotes.. I'm getting sloppy! EEK

Dim MyDate
Set Mydate = Day(Date)

If MyDate = 1 then
Set Mydate = "Monday"
Elseif Mydate = 2 Then
Set Mydate = "Tuesday"
...etc...

End If

This should work.

-Josh ------------------
-JPeters
Got a helpful tip for Access Users? Check out and contribute to 'How to Keep Your Databases from becoming Overwhelming!'
thread181-293590
jpeters@guidemail.com
------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top