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

Dates

Status
Not open for further replies.

walks

Technical User
May 7, 2001
203
CA
Im running a sports site and have the weekly games on the side of my webpage. Currently I have it set to

nWeek = DateAdd("d",+7,date())

so it shows games from the current date plus 7 days right, what is the code if I just wanted to show games from Monday through Sunday every week and refreshing for the new upcoming games for the following Monday through Sunday??
 
You could create a dateStart and dateEnd variable to hold the starting date and end date for the week. Then using the weekday function you could get the current day of the week from Now and add or subtract the necessary number of days to create your dateStart and dateEnd variables. To get the next week you could date add 7 days to both like your doing above.
Code:
Dim startDate, endDate
startDate = dateAdd("d",(weekday(now)*-1)+1,now) 'subtract the numeric day of the week from todays date to get first day of the week
endDate = dateAdd("d",7 - weekday(now),now) 'add the number of days left in the week from today
Response.Write &quot;Start:&quot;&formatDateTime(startDate,1)&&quot;<br>&quot;
Response.Write &quot;End:&quot;&formatDateTime(endDate,1)&&quot;<br>&quot;

Dim nextWeekSt, nextWeekEn
nextWeekSt = dateAdd(&quot;d&quot;,7,startDate)
nextWeekEn = dateAdd(&quot;d&quot;,7,endDate)
Response.Write &quot;Next Start:&quot;&formatDateTime(nextWeekSt,1)&&quot;<br>&quot;
Response.Write &quot;Next End:&quot;&formatDateTime(nextWeekEn,1)&&quot;<br>&quot;
That calculates a start and end date for the current week starting on sunday, ending on saturday. As mentioned above to get the next week you only need to add 7 days to the start and end of the current week. Obviously if you wanted monday to sunday you could just add an additional 1 to the dateAdd's above in the first calculation. ie
Code:
startDate = dateAdd(&quot;d&quot;,(weekday(now)*-1)+2,now)
Hope that helps,
-Tarwn &quot;The problem with a kludge is eventually you're going to have to back and do it right.&quot; - Programmers Saying (The Wiz Biz - Rick Cook)
&quot;Your a geek!&quot; - My Girlfriends saying
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top