Solved

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

Posted on 2013-01-26
8
323 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 270 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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 demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now