Solved

ASP - Get Current Month, Current Year number then navigate between months

Posted on 2004-09-14
8
716 Views
Last Modified: 2006-11-17
Hello,

I have a Web page called "month.asp".  I am wanting to list the current month and Year (i.e Septemeber, 2004).  Then I will want to write it.  Then, next to the month name will be two graphic arrows that will allow a user to navigate to the previous month or to the next month while staying on "month.asp".

This is not a calendar.  I am just looking to navigate through the months.

Can you please help with a code example?

Thank you in advance.
0
Comment
Question by:rudyflyer
  • 5
  • 3
8 Comments
 
LVL 19

Expert Comment

by:peh803
ID: 12054890
Probably not the prettiest example available, but it works -- I know that for sure..
regards,
peh803
<%
Dim sDate
Dim sCurrMonth
Dim sForward
Dim sBack
Dim sBackMonthVal, sForwardMonthVal
sBack = ""
sForward = ""
sDisplayMonth = ""
if len(trim(request("forward")))>0 then
  sForward = request("forward")
end if

if len(trim(request("back")))>0 then
  sBack = request("back")
end if

sDate = date()
sCurrMonth = Month(date())

if len(request("currmonth"))>0 then
  sCurrMonth = request("currmonth")
end if

if sBack<>"" then
'  sDisplayMonth = sCurrMonth-1
end if

if sForward<>"" then
'  sDisplayMonth = sCurrMonth+1
end if

if sDisplayMonth="" then
  sDisplayMonth = sCurrMonth
end if

if sDisplayMonth<1 then
  sDisplayMonth=12
end if

if sDisplayMonth>12 then
  sDisplayMonth=1
end if

sBackMonthVal = sCurrMonth-1
sForwardMonthVal = sCurrMonth+1
if sBackMonthVal<1 then sBackMonthVal=12

if sForwardMonthVal>12 then sForwardMonthVal=1
%>
<a href="month.asp?back=1&currmonth=<%=sBackMonthVal%>"> <-- </a><%=MonthName(sDisplayMonth)%><a href="month.asp?forward=1&currmonth=<%=sForwardMonthVal%>"> --> </a>
0
 
LVL 19

Expert Comment

by:peh803
ID: 12054927
much cleaner version:

<%
Dim sDate
Dim sCurrMonth
Dim sBackMonthVal
Dim sForwardMonthVal

sDisplayMonth = ""
sDate         = date()
sCurrMonth    = Month(date())

if len(request("currmonth"))>0 then
  sCurrMonth = request("currmonth")
end if

if sDisplayMonth="" then
  sDisplayMonth = sCurrMonth
end if

if sDisplayMonth<1 then
  sDisplayMonth=12
end if

if sDisplayMonth>12 then
  sDisplayMonth=1
end if

sBackMonthVal = sCurrMonth-1
sForwardMonthVal = sCurrMonth+1
if sBackMonthVal<1 then sBackMonthVal=12
if sForwardMonthVal>12 then sForwardMonthVal=1

%>
<a href="month.asp?currmonth=<%=sBackMonthVal%>"> <-- </a><%=MonthName(sDisplayMonth)%><a href="month.asp?currmonth=<%=sForwardMonthVal%>"> --> </a>
0
 

Author Comment

by:rudyflyer
ID: 12055260
peh803,

This is excellent.  One other thing if you don't mind.  Is it possible to also get the year?  So, when a user navigates from month to month a parameter is passed indicating the year.  Then, when to gets to January the year changes to the next year.


THanks a lot.
0
 
LVL 19

Expert Comment

by:peh803
ID: 12055594
hm, okay, I should be able to include that (although it wasn't part of the original specifications....).

Give me a minute.  

Also, I'd be glad to accept more points for the additional question (2 for 1) :)

Glad you're happy so far,
peh803
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:rudyflyer
ID: 12055665
peh803,

Opps.  I meant to increase the points.  Sorry about that.  I doubled it to 250.
0
 
LVL 19

Accepted Solution

by:
peh803 earned 250 total points
ID: 12055703
Thanks for the points increase.  Here's your solution :)

Enjoy!!

peh803

<%
Dim sDate
Dim sCurrMonth
Dim sBackMonthVal
Dim sForwardMonthVal
Dim sCurrentYear
Dim sBackYear
Dim sForwardYear
sDisplayMonth = ""
sDate         = date()
sCurrMonth    = Month(date())
sCurrentYear  = Year(date())

if len(request("curryear"))>0 then
  sCurrentYear = request("curryear")
end if

sBackYear     = sCurrentYear
sForwardYear  = sCurrentYear

if len(request("currmonth"))>0 then
  sCurrMonth = request("currmonth")
end if

if sDisplayMonth="" then
  sDisplayMonth = sCurrMonth
end if

if sDisplayMonth<1 then
  sDisplayMonth=12
end if

if sDisplayMonth>12 then
  sDisplayMonth=1
end if

sBackMonthVal = sCurrMonth-1
sForwardMonthVal = sCurrMonth+1

if sBackMonthVal<1 then
  sBackMonthVal=12
  sBackYear = sCurrentYear - 1
end if

if sForwardMonthVal>12 then
  sForwardMonthVal=1
  sForwardYear = sCurrentYear + 1
end if

%>
<a href="month.asp?currmonth=<%=sBackMonthVal%>&curryear=<%=sBackYear%>"> <-- </a><%=MonthName(sDisplayMonth)%>, <%=sCurrentYear%><a href="month.asp?currmonth=<%=sForwardMonthVal%>&curryear=<%=sForwardYear%>"> --> </a>
0
 

Author Comment

by:rudyflyer
ID: 12056024
peh803,

Thanks a lot for the speedy replys and the help.  Much appreciated.
0
 
LVL 19

Expert Comment

by:peh803
ID: 12056677
no problem at all...always glad to help.

Take care, and look me up for future ?'s!

peh803
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now