| << | Track Adsense Clicks via Analytics | Yes I'm here 24/7 to serve you | >> |
| posted at 15:18:52 By Flipping Heck! | Posted In Coding |
I've been writing an application for work that requires me to display one weeks worth of data, starting on a Monday and ending on a Sunday. Below is the code that will find the first Monday and subsequent days dates.
This code would be useful for a calendar system, time-tracking application, project management etc.
<%
'** Get Today's Date
CurrentDate=FormatDateTime(Now,2)
'** Get Which day of the week it is (number)
FirstDayOfTheWeek=Weekday(CurrentDate, 2)
'** Find how many days until Sunday are left
LastDayOfTheWeek=7-FirstDayOfTheWeek
'** Beginning of the week (Monday) Date
FindMonday=DateAdd("d",-FirstDayOfTheWeek, CurrentDate)+1
'** End of the Week (Sunday) Date
FindSunday=DateAdd("d", LastDayOfTheWeek, CurrentDate)
'** Work out the dates for various days
Monday=FindMonday
Tuesday=DateAdd("d", FindMonday, 1)
Wednesday=DateAdd("d", FindMonday, 2)
Thursday=DateAdd("d", FindMonday, 3)
Friday=DateAdd("d", FindMonday, 4)
Saturday=DateAdd("d", FindMonday, 5)
Sunday=DateAdd("d", FindMonday, 6)
'** Write Out the days and dates
Response.Write("Mon - "&Monday&"<br>")
Response.Write("Tue - "&Tuesday&"<br>")
Response.Write("Wed - "&Wednesday&"<br>")
Response.Write("Thur - "&Thursday&"<br>")
Response.Write("Fri - "&Friday&"<br>")
Response.Write("Sat - "&Saturday&"<br>")
Response.Write("Sun - "&Sunday&"<br>")
%>
Please feel free to use the above code in any project - a mention would be nice too 
| Click To View Comments | Trackback URL | |
| << | Track Adsense Clicks via Analytics | Yes I'm here 24/7 to serve you | >> |





View the Tag Cloud or View the Category Cloud