to convert a month to previous month

E

eddie wang

How to convert a month to previous month in a very easy way? For
example, I have AUGUST, but I want JULY to return.

Thanks.
 
B

Bob Barrows

eddie said:
How to convert a month to previous month in a very easy way? For
example, I have AUGUST, but I want JULY to return.
Subtract one month ...













.... you may want to provide a little more detail if you want a helpful
answer.

Here's my guess as to what you want:

dim d
d=#8/23/2003#
response.write "This month: " & monthname(month(d)) & "<BR>"
d=dateadd("m",-1,d)
response.write "Last month: " & monthname(month(d)) & "<BR>"


Bob Barrows
 
E

eddie wang

Thanks for the response.

what is d=AUGUST instead of your example d=#8/23/2003#??
 
B

Bob Barrows

eddie said:
Thanks for the response.

what is d=AUGUST instead of your example d=#8/23/2003#??

Assuming that this is what you mean:

d="AUGUST"

then you will need to do a select case:

dim lastmonth, d
d="AUGUST"
select case d
case "JANUARY": lastmonth="DECEMBER"
case "FEBRUARY": lastmonth="JANUARY"
....
end select

Bob Barrows
 
E

eddie wang

What is I only have AUGUST (not month/day/year) as my variable?

How to just convert AUGUST to JULY?

Thanks.
 
B

Bob Barrows

eddie said:
What is I only have AUGUST (not month/day/year) as my variable?

How to just convert AUGUST to JULY?

Thanks.

Assuming that this is what you mean:

d="AUGUST"

then you will need to do a select case:

dim lastmonth, d
d="AUGUST"
select case d
case "JANUARY": lastmonth="DECEMBER"
case "FEBRUARY": lastmonth="JANUARY"
....
end select

Bob Barrows
 
E

Evertjan.

eddie wang wrote on 09 okt 2003 in microsoft.public.inetserver.asp.general:
What is I only have AUGUST (not month/day/year) as my variable?

How to just convert AUGUST to JULY?

<%
mn=split("January/February/March/April/May/June/"&_
"July/August/September/October/November/December","/")

function lastmn(d)
lastmn = "Error"
for i=0 to 11
if ucase(d)=ucase(mn(i)) then
lastmn = mn((i+11) mod 12)
exit for
end if
next
end function

response.write lastmn("august") & "<br>"
response.write lastmn("JANUARY")
%>
 
D

dlbjr

Function MonthDiff(strMonth,intAmount)
MonthDiff = "Error"
strMonth = UCase(Trim(strMonth))
intMonth = 0
Select Case strMonth
Case "JANUARY" intMonth = 1
Case "FEBRUARY" intMonth = 2
Case "MARCH" intMonth = 3
Case "APRIL" intMonth = 4
Case "MAY" intMonth = 5
Case "JUNE" intMonth = 6
Case "JULY" intMonth = 7
Case "AUGUST" intMonth = 8
Case "SEPTEMBER" intMonth = 9
Case "OCTOBER" intMonth = 10
Case "NOVEMBER" intMonth = 11
Case "DECEMBER" intMonth = 12
End Select
If IsNumeric(intAmount) And intMonth > 0 Then
MonthDiff =
MonthName(DatePart("m",DateAdd("m",intAmount,DateSerial(Year(Date),intMonth,
1))),False)
End If
End Function

strMonth = "AUGUST"
Response.Write MonthDiff(strMonth,-1)

-dlbjr

Discerning resolutions for the alms
 
C

Chris Hohmann

eddie wang said:
How to convert a month to previous month in a very easy way? For
example, I have AUGUST, but I want JULY to return.

Thanks.

Dim sMonth : sMonth = "AUGUST"
Response.Write UCase(MonthName(Month(DateAdd("m",-1,sMonth & " 1492"))))

HTH
-Chris Hohmann
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top