Link to home
Start Free TrialLog in
Avatar of UName10
UName10Flag for United Kingdom of Great Britain and Northern Ireland

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:

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

Open in new window


Many thanks.
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

On line 27 you are checking against iDayname, a variable that I don't see defined here.

Maybe you can just change Weekday(i) to Weekday(i-1) on line 32 (twice)?
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))

Open in new window

Then also change:
iDay = Weekday(dtCurrentDateTime, 2)

Open in new window

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

%>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of UName10

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.
Avatar of UName10

ASKER

Perfect