UName10
asked on
Need to start a Day of week function on Monday instead of Sunday
I've got a function, but need to start it on Monday instead of Sunday.. Here's the function:
Many thanks.
Public Sub CreateDayNameTimeSelectionBox(strObjectName, dtCurrentDateTime, AllowNone)
Dim iDay
Dim iHour
Dim iMin
Dim i
Dim strSelected
if dtCurrentDateTime = "0" then
dtCurrentDateTime = Now()
end if
If IsNull(dtCurrentDateTime) then
iDay = ""
iHour = ""
iMin = ""
Else
dtCurrentDateTime = CDate(dtCurrentDateTime)
iDay = Weekday(dtCurrentDateTime)
iHour = Hour(dtCurrentDateTime)
iMin = Minute(dtCurrentDateTime)
End If
%>
<select name="<% = strObjectName %>_dayName" ID="Select1" class="input-list">
<%
If AllowNone = True then
%><option value=""> - </option><%
end if
For i = 1 to 7
if i = idayName then
strSelected = " SELECTED "
else
strSelected = ""
end if
%><option value="<% = WeekdayName(i) %>"<% = strSelected %>><% = WeekdayName(i) %></option><%
Next
%>
</select>
<select name="<% = strObjectName %>_Hour" class="input-list">
<%
If AllowNone = True then
%><option value=""> - </option><%
End if
For i = 0 to 23
if i = iHour then
strSelected = " SELECTED "
Else
strSelected = ""
end if
%><option value="<% = Right("00" & Trim(CStr(i)), 2) %>" <% = strSelected %>><% = Right("00" & Trim(CStr(i)), 2) %></option><%
Next
%>
</select>
<select name="<% = strObjectName %>_Min" class="input-list">
<%
If AllowNone = True then
%><option value=""> - </option><%
End if
For i = 0 to 59
if i = iMin then
strSelected = " SELECTED "
Else
strSelected = ""
end if
%><option value="<% = Right("00" & Trim(CStr(i)), 2) %>" <% = strSelected %>><% = Right("00" & Trim(CStr(i)), 2) %></option><%
Next
%>
</select>
<%
End Sub
Many thanks.
Actually, your code works just fine for me (but that may be a regional setting). In the manual it does says to add , 1 as argument to make monday the first day.
I think this is what you need:
WeekdayName(Weekday(i, 2))
Then also change:
iDay = Weekday(dtCurrentDateTime, 2)
Note again that this doesn't work for me, whereas your original code did.
Ah, think I found it, sorry for the confusing posts. Here's my working test code:
<%
dtCurrentDateTime = Now()
iDay = Weekday(dtCurrentDateTime,2)
response.write dtCurrentDateTime & " (weekday = " & iDay & ")<br>"
For i = 1 to 7
if i = iDay then
strSelected = " SELECTED "
else
strSelected = ""
end if
%>i=<%=i%>, option value="<% = WeekdayName(i,,2) %>"<% = strSelected %> : <% = WeekdayName(i,,2) %><br><%
Next
%>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ha ha no worries, I've made lots of confusing posts today! It was well explained thank you, and works perfectly.
Many thanks for helping.
Many thanks for helping.
ASKER
Perfect
Maybe you can just change Weekday(i) to Weekday(i-1) on line 32 (twice)?