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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date display change

Status
Not open for further replies.

BarryMVS

IS-IT--Management
Apr 17, 2003
172
GB
Hi all,

Im trying to display a seven day calender. I have managed to configure the display format and to get it to increase the date by one for each day, but if I start my seven day display on the 29th July, it will finish on the 35th July!

How can I get it to roll over to the next month?

I know this is probably quite in depth, but I can not find any information on the web regarding building a calender. I have tried taking one aprt, but I can not get it to adapt. (I must be doing something wrong.)

Any ideas would be most welcomed.

Thanks,

Barry

ICT Network Administrator
IT Services Manager
 
is the calendar code ur code? or is it from the web? if its urs then i suggest u give us the code where u loop for the 7 days...

Note:
try the web, i guess all these types of calendars have already been built. i have one for an enitre month...

Known is handfull, Unknown is worldfull
 
My guess is your looping from 0 to 6 and adding your counter to the current day, this of course causes non-legal dates to come out. Instead why not try using the DateAdd function to increment the date object? this will automatically rollowver to new months/years for you:
Code:
Dim i, myDate
myDate = Now()
For i = 0 to 6
   'display the date in short date format
   Response.Write FormatDateTime(myDate,2)
   'increment the date by one day
   myDate = DateAdd("d",1,myDate)
Next

Since your using the Date type here you should not have to worry about month/year rollovers or even leap years.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
vbKris,

I have tried adapting a calednder I got off the web, but I can't get it to work.

This is the original code that I put together.
Code:
startdate = request.form("mdate")						
		day1 = startdate
		day2 = Day(startdate)+1 & " " & MonthName(Month(startdate), True) & " " & Year(startdate)
		day3 = Day(startdate)+2 & " " & MonthName(Month(startdate), True) & " " & Year(startdate)
		day4 = Day(startdate)+3 & " " & MonthName(Month(startdate), True) & " " & Year(startdate)
		day5 = Day(startdate)+4 & " " & MonthName(Month(startdate), True) & " " & Year(startdate)
		day6 = Day(startdate)+5 & " " & MonthName(Month(startdate), True) & " " & Year(startdate)
		day7 = Day(startdate)+6 & " " & MonthName(Month(startdate), True) & " " & Year(startdate)

As you can see, this just increases the day by one each time thus causing the problem I described.

I need some code that will work out the days for each month and then change month if those days run out, or something like that.

Any help is most welcomed.

Cheers,

Barry

ICT Network Administrator
IT Services Manager
 
Tarwin,

Thanks.

Code:
day1 = startdate
day2 = DateAdd("d",1,startdate)
day3 = DateAdd("d",2,startdate)
day4 = DateAdd("d",3,startdate)
day5 = DateAdd("d",4,startdate)
day6 = DateAdd("d",5,startdate)
day7 = DateAdd("d",6,startdate)

Works fine.

Cheers for your help.

Barry

ICT Network Administrator
IT Services Manager
 
Tarwin,

Got a problem. I'm displaying my date format as dd mmm yyyy ie 12 Jul 2004, but DateAdd changes it to dd/mm/yyyy.

Is there any code I can add to the above to make the date format that I want or do I need to run the format date line that I have listed above.

Thanks for your help.

Barry

ICT Network Administrator
IT Services Manager
 
This will display date in mmm dd yyyy format as you want:

Code:
Dim i, curDate, myDate, theDate
curDate = Date()
For i = 0 to 6
   'increment the date by one day
   curDate = DateAdd("d",1,curDate)
   theDate = split(curDate, "/")
   myDate = Left(MonthName(theDate(0)),3) & " " & theDate(1) & " " & theDate(2)
   Response.Write myDate & "<br>"
Next
 
i made a calendar.asp page, that's a full year calendar, and whenthe month value changed i would build the next block.

easiest thing to do this would be :

startdate = cdate(startdate) ' this is just to remove times etc.
currentmonth = month(startdate)
for d=0 to 6 ' did this for easy math in loop
if month(startdate) <> currentmonth then
currentmonth = month(startdate)
response.write "monthheader" ' whatever
end if
response.write monthname(currentmonth) & (startdate + d)
next


[thumbsup2]DreX
aKa - Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top