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

Date Troubles...

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
GB
I'm using the following code to list the days of the working week so that users can view a list for that particular day. The problem is that at the end of the every month it continues beyond the correct date (so that it goes 30/11/01 then 31/11/01 then 32/11/01) until the next week starts and it then seems to correct itself.

How can I correct this error?

Thanks everyone....

<%
WeekBeginning = DateAdd(&quot;d&quot;, 1 - weekday(date), Date)

MondayDate = DatePart(&quot;d&quot;, WeekBeginning) + 1 & &quot;/&quot; & _
DatePart(&quot;m&quot;, WeekBeginning) & &quot;/&quot; & _
DatePart(&quot;YYYY&quot;, WeekBeginning)
TuesdayDate = DatePart(&quot;d&quot;, WeekBeginning) + 2 & &quot;/&quot; & _
DatePart(&quot;m&quot;, WeekBeginning) & &quot;/&quot; & _
DatePart(&quot;YYYY&quot;, WeekBeginning)
WednesdayDate = DatePart(&quot;d&quot;, WeekBeginning) + 3 & &quot;/&quot; & _
DatePart(&quot;m&quot;, WeekBeginning) & &quot;/&quot; & _
DatePart(&quot;YYYY&quot;, WeekBeginning)
ThursdayDate = DatePart(&quot;d&quot;, WeekBeginning) + 4 & &quot;/&quot; & _
DatePart(&quot;m&quot;, WeekBeginning) & &quot;/&quot; & _
DatePart(&quot;YYYY&quot;, WeekBeginning)
FridayDate = DatePart(&quot;d&quot;, WeekBeginning) + 5 & &quot;/&quot; & _
DatePart(&quot;m&quot;, WeekBeginning) & &quot;/&quot; & _
DatePart(&quot;YYYY&quot;, WeekBeginning)
%>
 
It might be you adding things on to each of the day dates.

You could try doing the dateadd for each day, and add 1 for each of then C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!
 
example:
FormatDateTime(Date, 2) 'display in mm/dd/yyyy format

<%
WeekBeginning = DateAdd(&quot;d&quot;, 1 - weekday(date), Date)

MondayDate = FormatDateTime(DateAdd(&quot;d&quot;, 1, WeekBeginning),2)
TuesdayDate = FormatDateTime(DateAdd(&quot;d&quot;, 2, WeekBeginning),2)
WednesdayDate = FormatDateTime(DateAdd(&quot;d&quot;, 3, WeekBeginning),2)
ThursdayDate = FormatDateTime(DateAdd(&quot;d&quot;, 4, WeekBeginning),2)
FridayDate = FormatDateTime(DateAdd(&quot;d&quot;, 5, WeekBeginning),2)

%>

 
Thank lobstah but I have to put it in the dd/mm/yy format... any suggestions? I edited the code in that way for that reason...

Cheers...
 
sorry about that, i overlooked that.....

how about splitting the date into an array and rearranging it?

<%
WeekBeginning = DateAdd(&quot;d&quot;, 1 - weekday(date), Date)

Dim arrDate
Dim arrWeekDate
Dim i
For i=1 To 5
arrDate = Split(FormatDateTime(DateAdd(&quot;d&quot;, i, WeekBeginning),2), &quot;/&quot;)
arrWeekDate(i) = Join(arrDate(1), &quot;/&quot;, arrDate(0), &quot;/&quot;, arrDate(2))
Next

MondayDate = arrWeekDate(1)
TuesdayDate = arrWeekDate(2)
WednesdayDate = arrWeekDate(3)
ThursdayDate = arrWeekDate(4)
FridayDate = arrWeekDate(5)
%>


How's that?




 
just tested it...

change the Join statement to:

arrWeekDate(i) = arrDate(1) & &quot;/&quot; & arrDate(0) & &quot;/&quot; & arrDate(2)

and set the array size in the dim statement:

Dim arrWeekDate(5)

works fine then.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top