Quick Datepart ?

maw230

somewhat competent
Local time
Today, 04:30
Joined
Dec 9, 2009
Messages
522
I cant seem to be able to use Datepart("d",Date()). I want the day number of today's date. is there a daynum function i cant remember?
 
thanks bob.
also, i need a date function that will give me the three letter Day abbrev. of a datefield.
im not having luck finding one.
 
great, thanks again. now, i need to format a 3-letter day abbrev into a number.

i.e. Format(Day_of_week,"#")
 
great, thanks again. now, i need to format a 3-letter day abbrev into a number.

i.e. Format(Day_of_week,"#")

I believe that one will take a custom function to accomplish (I don't know of anything else that will, but perhaps someone else does).

Here's a function you can place in a STANDARD module (not form or report module) and then you can call it when you need to like

GetDayNum("Fri")

or

GetDayNum([FieldName])


Code:
Function GetDayNum(strDay As String) As Integer
    Select Case strDay
    Case "Sun", "Sunday"
        GetDayNum = 1
    Case "Mon", "Monday"
        GetDayNum = 2
    Case "Tue", "Tuesday"
        GetDayNum = 3
    Case "Wed", "Wednesday"
        GetDayNum = 4
    Case "Thu", "Thursday"
        GetDayNum = 5
    Case "Fri", "Friday"
        GetDayNum = 6
    Case "Sat", "Saturday"
        GetDayNum = 7
    End Select
End Function
 
Weekday(Date()) will return a number, 1 = Sunday, 2 = Monday, etc.

But that's only if you start with a valid date, not "Mon", "Tue", etc.
 
Weekday(Date()) will return a number, 1 = Sunday, 2 = Monday, etc.

But that's only if you start with a valid date, not "Mon", "Tue", etc.
And I think the "Mon", "Tue", etc. is where they were coming from on the last question.
 
And I think the "Mon", "Tue", etc. is where they were coming from on the last question.

It may be possible to do it all at once, just use:

Format(Date(), "ddd")
Weekday(Date())

Depends on where the info is going though.
 
It may be possible to do it all at once, just use:

Format(Date(), "ddd")
Weekday(Date())

Depends on where the info is going though.
True - I was going off of the assumption that it was not happening like that. But if it is; then it is much simpler and doesn't need the function. If not, then I THINK we need that custom function.
 
True - I was going off of the assumption that it was not happening like that. But if it is; then it is much simpler and doesn't need the function. If not, then I THINK we need that custom function.

Yeah I don't know any other way to take the date abbreviation and generate a number without that.
 
Oh, and the function would need to be adjusted depending on if the user considers Sunday to be day 1 or Monday to be day 1.
 
Hi -

Here's a function I've had laying around for a while -

Code:
Public Function RtnDayNum(pstrDayName As String) As Integer
'*******************************************
'Purpose:   Returns day number (1 - 7)
'           when provided a complete or partial
'           Day name.
'Coded by:  raskew
'Input:     From debug (immediate) window:
'           1) ? RtnDayNum("Tuesday")
'           1) ? RtnDayNum("Fri")
'Output:    1) 3
'           2) 6
'*******************************************

Dim strHold  As String
Dim strDay As String
Dim intDay As Integer

   strDay = "SunMonTueWedThuFriSat"
   strHold = Left(pstrDayName, 3)
   intDay = InStr(strDay, strHold)
   RtnDayNum = intDay \ 3 + 1

End Function

Bob
 
Thanks Bob. :) <embarrassed> :o

I should have known. That is similar to other code which you've come up with and I should have gone and looked first.
 

Users who are viewing this thread

Back
Top Bottom