Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need to start a Day of week function on Monday instead of Sunday

Posted on 2013-01-26
8
Medium Priority
?
331 Views
Last Modified: 2013-01-26
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.
0
Comment
Question by:UName10
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
8 Comments
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38823095
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)?
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38823104
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.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38823108
I think this is what you need:
WeekdayName(Weekday(i, 2))

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38823112
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.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38823124
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

0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 1080 total points
ID: 38823127
So your adjusted code would be:
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,2)
        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 = iDay then
				strSelected = " SELECTED "
			else
				strSelected = ""
			end if
			%><option value="<% = WeekdayName(i,,2) %>"<% = strSelected %>><% = WeekdayName(i,,2) %></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

0
 

Author Comment

by:UName10
ID: 38823138
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.
0
 

Author Closing Comment

by:UName10
ID: 38823139
Perfect
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question