Date formats

mikemaki

Registered User.
Local time
Today, 14:37
Joined
Mar 1, 2001
Messages
81
This is one of those problems that can be compared to a thorn in your foot. It's small, but it's still slowing me down. When I run the following code:

strAbrevMonth = Format(intCurrMonth, "mmm")

strAbrevMonth is always sey to 'Jan.' Even when I hardcode a 9 into the statement, strAbrevMonth is set to 'Jan.' Any ideas as to why?
 
Mike,

Format(SomeDate, "mmm") will give you the name of the month.
Format(Date, "mmm") should return "Sep" - for todays date
Format("12/12/2004", "mmm") should return "Dec"
Format("12/12/2004", "m") should return 12

Wayne
 
When you treat a number as a date it gets converted to a date. The value 0 is treated as 30-Dec-1899. The number 1 is seen as 01-Jan-1900.

Therefore, as you are passing the number nine to be formatted it is being treated as 09-Jan-1900. And that's why it continues to return as Jan.

Try this function instead:

Code:
Public Function GetMonth(ByVal intMonth As Integer) As String
    If intMonth < 1 And intMonth > 12 Then Exit Function
    GetMonth = Format(DateSerial(Year(Date), intMonth, 1))
End Function

Pass your number:

i.e.

Code:
strAbrevMonth = GetMonth(intCurrMonth)
 

Users who are viewing this thread

Back
Top Bottom