Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

Help tweaking a function for a time and date option select

I've got some time and date functions, but currently the time and date are joined together, whereas I'd like to separate out the time from the date from one of them.

When I use the 'CreateTimeDateSelectionBox' function, it includes: Day, Month, Year, Hour and Minute, but I just need an extra one for Hour and Minute.

Here's the functions code:

<%
Sub CreateSelectOption(byVal Value, byVal Display, byVal CurrentValue)
    %><option value="<% = Value %>" <% = GetSelectStatus_FromValues(Value,CurrentValue) %>><% = Display %></option><%
End Sub

Public Sub CreateDateTimeSelectionBox(strObjectName, dtCurrentDateTime, AllowNone)
    Dim iHour
    Dim iMin
    Dim i
    Dim strSelected
    if dtCurrentDateTime = "0" then
        dtCurrentDateTime = Now()
    end if
    If IsNull(dtCurrentDateTime) then
        iHour = ""
        iMin = ""
    Else
        dtCurrentDateTime = CDate(dtCurrentDateTime)
        iHour = Hour(dtCurrentDateTime)
        iMin = Minute(dtCurrentDateTime)
    End If
    CreateDateSelectionBox strObjectName, dtCurrentDateTime, AllowNone
    %>
    <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

Public Sub CreateDateSelectionBox(strObjectName, dtCurrentDate, AllowNone)
	Dim iDay
	Dim iMonth
	Dim iYear
	Dim iYearCount
	Dim strSelected
	Dim i
	if dtCurrentDate = "0" then
		dtCurrentDate = Date()
	end if
	
	if len(""&dtCurrentDate) > 0 then
	    iDay = Day(dtCurrentDate)
	    iMonth = Month(dtCurrentDate)
	    iYear = Year(dtCurrentDate)
	else
		iDay = 0
		iMonth = 0
		iYear = 0
	end if
	%>
	<select name="<% = strObjectName %>_Day" ID="Select1" class="input-list">
		<%
		If AllowNone = True then
		    %><option value=""> - </option><%
		end if
		For i = 1 to 31
			if i = iDay then
				strSelected = " SELECTED "
			else
				strSelected = ""
			end if
			%><option value="<% = i %>"<% = strSelected %>><% = i %></option><%
		Next
		%>
	</select>
	<select name="<% = strObjectName %>_Month" ID="Select2" class="input-list">
		<%
		If AllowNone = True then
		    %><option value=""> - </option><%
		end if
		For i = 1 to 12
			if i = iMonth then
				strSelected = " SELECTED "
			else
				strSelected = ""
			end if
			%><option value ="<% = i %>"<% = strSelected %>><% = MonthName(i) %></option><%
		Next
		%>
	</select>
	<select name="<% = strObjectName %>_Year" ID="Select3" class="input-list">
		<%
		If AllowNone = True then
		    %><option value=""> - </option><%
		end if
		loopyear = iyear
		if loopyear = 0 then loopyear = year(now)
            For i = Year(Now) - 1 To Year(Now) + 10
			if i = iYear then
				strSelected = " SELECTED "
			else
				strSelected = ""
			end if
			%><option value="<% = i %>"<% = strSelected %>><% = i %></option><%
		Next
		%>
	</select>
	<%
End Sub

Public Sub CreateCCDateSelectionBox(strObjectName, dtCurrentDate, AllowNone, IsFromDate)
	Dim iDay
	Dim iMonth
	Dim iYear
	Dim iYearCount
	Dim strSelected
	Dim iYearStart
	Dim iYearEnd
	Dim i
	if dtCurrentDate = "0" then
		dtCurrentDate = Date()
	end if
	if IsNull(dtCurrentDate) then
	    iDay = ""
	    iMonth = ""
	    iYear = ""
'	    iYear = Year(Date())
	    iYearCount = Year(Date())
	else
	    iDay = Day(dtCurrentDate)
	    iMonth = Month(dtCurrentDate)
	    iYear = Year(dtCurrentDate)
	    iYearCount = iYear
	end if
	If IsFromDate = True then
	    iYearStart = iYearCount - 1
	    iYearEnd = Year(Date())
	Else
	    iYearStart = Year(Date())
	    iYearEnd = iYearCount + 10
	End if
	%>
	<input type="hidden" name="<% = strObjectName %>_Day" value="1" />
	<select name="<% = strObjectName %>_Month" ID="Select5" class="input-list">
		<%
		If AllowNone = True then
		    %><option value=""> - </option><%
		end if
		For i = 1 to 12
			if i = iMonth then
				strSelected = " SELECTED "
			else
				strSelected = ""
			end if
			%><option value ="<% = i %>"<% = strSelected %>><% = Right("00" & Trim(CStr(i)), 2) %></option><%
		Next
		%>
	</select> / 
	<select name="<% = strObjectName %>_Year" ID="Select6" class="input-list">
		<%
		If AllowNone = True then
		    %><option value=""> - </option><%
		end if
		For i = iYearStart to iYearEnd
			if i = iYear then
				strSelected = " SELECTED "
			else
				strSelected = ""
			end if
			%><option value="<% = i %>"<% = strSelected %>><% = Right(i, 4) %></option><%
		Next
		%>
	</select>
	<%
End Sub

Public Function GetFormDate(byVal strObjectName)
	Dim sDate
	if IsNull(Request(strObjectName & "_Day")) or IsNull(Request(strObjectName & "_Month")) or IsNull(Request(strObjectName & "_Year")) then
		sDate = Null
	elseif Trim(CStr(Request(strObjectName & "_Day"))) = "0" or Trim(CStr(Request(strObjectName & "_Month"))) = "0" or Trim(CStr(Request(strObjectName & "_Year"))) = "0" then
		sDate = Null
	elseif Trim(CStr(Request(strObjectName & "_Day"))) = "" or Trim(CStr(Request(strObjectName & "_Month"))) = "" or Trim(CStr(Request(strObjectName & "_Year"))) = "" then
		sDate = Null
	else
		sDate = CleanResponseText(Request(strObjectName & "_Day")) & " " & MonthName(CleanResponseText(Request(strObjectName & "_Month"))) & " " & CleanResponseText(Request(strObjectName & "_Year"))
	end if
	If IsDate(sDate) then
		GetFormDate = sDate
	else
		GetFormDate = Null
	end if
End Function

Public Function GetFormDateTime(byVal strObjectName)
	Dim sDate
	if IsNull(Request(strObjectName & "_Day")) or IsNull(Request(strObjectName & "_Month")) or IsNull(Request(strObjectName & "_Year"))  or IsNull(Request(strObjectName & "_Hour")) or IsNull(Request(strObjectName & "_Min")) then
		sDate = Null
	elseif Trim(CStr(Request(strObjectName & "_Day"))) = "0" or Trim(CStr(Request(strObjectName & "_Month"))) = "0" or Trim(CStr(Request(strObjectName & "_Year"))) = "0" then
		sDate = Null
	elseif Trim(CStr(Request(strObjectName & "_Day"))) = "" or Trim(CStr(Request(strObjectName & "_Month"))) = "" or Trim(CStr(Request(strObjectName & "_Year"))) = "" or Trim(CStr(Request(strObjectName & "_Hour"))) = "" or Trim(CStr(Request(strObjectName & "_Min"))) = "" then
		sDate = Null
	else
		sDate = CleanResponseText(Request(strObjectName & "_Day")) & " " & MonthName(CleanResponseText(Request(strObjectName & "_Month"))) & " " & CleanResponseText(Request(strObjectName & "_Year")) & " " & CleanResponseText(Request(strObjectName & "_Hour")) & ":" & CleanResponseText(Request(strObjectName & "_Min"))
	end if
	If IsDate(sDate) then
		GetFormDateTime = sDate
	else
		GetFormDateTime = Null
	end if
End Function

Public Function StartHoverClickDiv(byVal strText)
	Dim sDivStream
	Dim strTitle
	Dim strAlert
	' Sort out the LineBreaks for JS and HTML
	strTitle = strText
	strAlert = strText
	strTitle = Replace(strTitle, "<br>", vbCrLf)
	strTitle = Replace(strTitle, "\n", vbCrLf)
	strAlert = Replace(strAlert, "<br>", "\n")
	strAlert = Replace(strAlert, vbCrLF, "\n")
	' Sort out JS {'} Quote problem
	strTitle = Replace(strTitle, "'", "\'")
	strTitle = Replace(strTitle, """", "\'")
	strAlert = Replace(strAlert, "'", "\'")
	strAlert = Replace(strAlert, """", "\'")
	sDivStream = "<div title=""" & strTitle & """ onClick=""javascript:alert('" & strAlert & "');"" style=""cursor: help;"">"
	StartHoverClickDiv = sDivStream
End Function

Public Function StartHoverDiv(byVal strText)
	Dim sDivStream
	Dim strTitle
	' Sort out the LineBreaks for JS and HTML
	strTitle = strText
	strTitle = Replace(strTitle, "<br>", vbCrLf)
	strTitle = Replace(strTitle, "\n", vbCrLf)
	' Sort out JS {'} Quote problem
	strTitle = Replace(strTitle, "'", "\'")
	strTitle = Replace(strTitle, """", "\'")
	sDivStream = "<div title=""" & strTitle & """ style=""cursor: help;"">"
	StartHoverDiv = sDivStream
End Function

Public Function MakeJavaSafeText(byVal Message)
    Message = Replace(Message, "\", "\\")
    Message = Replace(Message, "\\n", "\n")
    Message = Replace(Message, "<br>", "\n")
    Message = Replace(Message, vbCrLf, "\n")
    MakeJavaSafeText = Message
End Function

Public Sub DoJavaAlert(byVal Message)
    %>
    <script language="javascript" type="text/javascript">
        <!--
            alert('<% = MakeJavaSafeText(Message) %>');
        //-->
    </script>
    <%
End Sub
Public Sub DoJavaRedirect(byVal URL)
    %>
    <script language="javascript" type="text/javascript">
        <!--
            document.location='<% = URL %>';
        //-->
    </script>
    <%
End Sub
%>

Open in new window


Any help much appreciated.
0
UName10
Asked:
UName10
  • 10
  • 6
1 Solution
 
Robert SchuttSoftware EngineerCommented:
So the option I proposed on your original question would be to add this copy of the function and call that from the code in the page:
Public Sub CreateTimeSelectionBox(strObjectName, dtCurrentDateTime, AllowNone)
    Dim iHour
    Dim iMin
    Dim i
    Dim strSelected
    if dtCurrentDateTime = "0" then
        dtCurrentDateTime = Now()
    end if
    If IsNull(dtCurrentDateTime) then
        iHour = ""
        iMin = ""
    Else
        dtCurrentDateTime = CDate(dtCurrentDateTime)
        iHour = Hour(dtCurrentDateTime)
        iMin = Minute(dtCurrentDateTime)
    End If
    %>
    <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
 
Robert SchuttSoftware EngineerCommented:
If you implemented the other option from your earlier question, I won't object if you just delete this question.
0
 
UName10Author Commented:
That's perfect - thank you very much . I'll award points as it was a separate query...

Thanks again for the help.
0
Technology Partners: 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!

 
UName10Author Commented:
Helpful and effective solution to fixing the function.
0
 
UName10Author Commented:
Hi,  there's another quick question if you don't mind...almost there!

Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'HTMLEncode'

/event-details.asp, line 73

Just testing it and I'm getting an error on the front end because my syntax is wrong; please excuse me, my brain's switched off...

Here's the event details page code where I'm bringing it in:


    <div class="time">
      <div class="hour"><%=server.HTMLEncode(""&hour(rs("ca_starttime")),true)%></div>
      <div><%=server.HTMLEncode(""&min(rs("ca_endtime")))%></div>
   </div>

Open in new window


If you could diagnose where I went wrong it'd be great, the final hurdle..

Many thanks.
0
 
Robert SchuttSoftware EngineerCommented:
What does the ,true parameter to HTMLEncode do there? I guess you could just delete it, but maybe it was left over from something else.
0
 
Robert SchuttSoftware EngineerCommented:
Just in general a bit of advice: check the logic instead of copying things around.

hour(rs("ca_starttime")) returns an integer, no need to use the trick with ""&

(also no need to use server.HTMLEncode on an integer)

It may however be needed to check for NULL value although maybe this field can not be NULL in the database so then it should be enough to use
<div class="time">
      <div class="hour"><%=hour(rs("ca_starttime"))%></div>
      <div><%=minute(rs("ca_endtime"))%></div>
   </div> 

Open in new window

Note that I changed min() to minute() as well.

EDIT: just realised there's also a possible copy error regarding start/end time in those 2 fields.
0
 
UName10Author Commented:
Thanks for checking...I changed it to the following, but getting a series of '0's now wherethe time should be on the page here:

    <div class="time">
      <div class="hour"><%=server.HTMLEncode(""&hour(hour(rs("ca_starttime"))))%></div>
      <div><%=server.HTMLEncode(""&minute(rs("ca_starttime")))%></div>
    </div>

    <div class="time">
      <div class="hour"><%=server.HTMLEncode(""&hour(hour(rs("ca_endtime"))))%></div>
      <div><%=server.HTMLEncode(""&minute(rs("ca_endtime")))%></div>
    </div>

It's saved in the database though fine..
0
 
UName10Author Commented:
Of if I use 'min' instead of 'minute', it gives me this error:

0
Microsoft VBScript runtime error '800a000d'

Type mismatch: 'min'

/event-details.asp, line 74

<!--#include virtual="/System/Startup_Public.asp"-->
<%
'response.write request.querystring

sql = "SELECT *,dbo.RemoveNonAlphaCharacters(ca_title) AS URL FROM CommunityArticles WHERE "&_ 
	" ca_live = 1 AND ca_franchise = '{"&session("PublicFranchiseGID")&"}' "&_ 
	"AND DATENAME(month,ca_startdate) = '"&getquery("m")&"' "&_ 
	"AND YEAR(ca_startdate) = "&cint(getquery("y"))&" "&_
	"AND dbo.RemoveNonAlphaCharacters(ca_title) = '"&getquery("a")&"';"
getrs rs,sql,""
	
if rs.recordcount = 0 then 
	response.write sql
	response.write "Event not found." : response.end
end if

If Session("PublicFranchiseGID") = "" then
    Response.Redirect "/"
End if

	sLink = "/" & lcase(session("publicfranchisename")) & "/events/" & year(rs("ca_startdate")) & "/" & monthname(month(rs("ca_startdate"))) & "/" & lcase(rs("URL")) & ".html"
	if not sLink = request.ServerVariables("HTTP_X_REWRITE_URL") then
		response.status = "301 Moved Permanently"
		response.addheader "Location", "http://www.inside-guides.co.uk" & sLink
		response.end
	end if

EnsurePageIsBasicHTTP

startdate = date()
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><%=server.HTMLEncode(""&rs("ca_title"))%> | <%=server.HTMLEncode(Session("PublicFranchiseName"))%>&nbsp;Events</title>
<meta name="Description" content="<%=server.HTMLEncode(""&rs("ca_title"))%> | <%=server.HTMLEncode(Session("PublicFranchiseName"))%>&nbsp;Events" />
<meta name="Keywords" content="<%=server.HTMLEncode(""&rs("ca_title"))%>, <%=server.HTMLEncode(Session("PublicFranchiseName"))%>, Events" />
<link rel="stylesheet" type="text/css" href="/css/hot-sneaks/jquery-ui-1.8.22.custom.css"/>
<!--#include virtual="/Assets/Templates/Public/Franchise/HeadCSS.asp"-->
<link rel="stylesheet" type="text/css" href="/css/EventDetails.css"/>
<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.22.custom.min.js"></script>
<script type="text/javascript">
	$(document).ready(function(e) {
        $('#datepicker').datepicker({
		dateFormat:'dd/mm/yy'
		});
    });
</script>
</head>
<body id="events">
<!--#include virtual="/Assets/Templates/Public/Franchise/Event-Details.asp"-->

                    <% if len(""&rs("ca_thumbnail"))>0 then %>
                    <div class="event_image"><a href="<%=url%>"><img alt="<%=Session("PublicFranchiseName")%> events" src="/includes/tn.asp?src=/LiveStorage/Uploads/image/CommunityArticles/<%=server.URLEncode(""&rs("ca_thumbnail"))%>" 
                        alt="<%=server.HTMLEncode(""&rs("ca_title"))%>" /></a></div>
                    <% end if %>

    <div class="date_section">
    <div class="date">
      <div class="month"><%=server.HTMLEncode(""&monthname(month(rs("ca_startdate")),true))%></div>
      <div><%=server.HTMLEncode(""&day(rs("ca_startdate")))%></div>
    </div>
      <div class="to">to</div>
    <div class="date">
      <div class="month"><%=server.HTMLEncode(""&monthname(month(rs("ca_enddate")),true))%></div>
      <div><%=server.HTMLEncode(""&day(rs("ca_enddate")))%></div>
    </div>
   </div>

    <div class="time">
      <div class="hour"><%=server.HTMLEncode(""&hour(hour(rs("ca_starttime"))))%></div>
      <div><%=server.HTMLEncode(""&min(rs("ca_starttime")))%></div>
    </div>

    <div class="time">
      <div class="hour"><%=server.HTMLEncode(""&hour(hour(rs("ca_endtime"))))%></div>
      <div><%=server.HTMLEncode(""&min(rs("ca_endtime")))%></div>
    </div>

    <ul class="event-address">
      <li><%=server.HTMLEncode(rs("ca_address1") & "")%></li>
      <li><%=server.HTMLEncode(rs("ca_address2") & "")%></li>
      <li><%=server.HTMLEncode(rs("ca_town") & "")%></li>
      <li><%=server.HTMLEncode(rs("ca_county") & "")%></li>
      <li><%=server.HTMLEncode(rs("ca_postcode") & "")%></li>
     </ul>

    <div class="article-details"><%=rs("ca_article")%></div>

    <% if len(""&rs("ca_fullimage"))>0 then %>
        <img src="/includes/tn.asp?src=/LiveStorage/Uploads/image/CommunityArticles/<%=server.URLEncode(""&rs("ca_fullimage"))%>" class="fullimage" />
    <% end if %>

    <% if len(""&rs("ca_location"))>0 then %>
    <div class="event-address"><h3><img src="/images/map.png" alt="event location" /> At <%=server.HTMLEncode(rs("ca_location"))%></h3></div>
    <% end if %>


<!--#include virtual="/Assets/Templates/Public/Franchise/TemplateEnd.asp"-->
</body>
</html>
<!--#include virtual="/System/Shutdown.asp"-->

Open in new window

0
 
UName10Author Commented:
Ok I got the hour to work by changing it to the following (can't get it to full 24 hr format though; it only says '19' for '1900' hours...

    <div class="time">
      <div class="hour"><%=server.HTMLEncode(""&hour(rs("ca_starttime")))%></div>
      <div><%=server.HTMLEncode(""&minute(rs("ca_starttime")))%></div>
    </div>

    <div class="time">
      <div class="hour"><%=server.HTMLEncode(""&hour(rs("ca_endtime")))%></div>
      <div><%=server.HTMLEncode(""&minute(rs("ca_endtime")))%></div>
    </div>

Open in new window


Hopefully manage to do the minute...
0
 
UName10Author Commented:
Hi Robert - I'm sorry I've just seen your reply from earlier; yes you're absolutely right - I'm just learning to be honest (keenly) and hope to write it all myself soon.

I'm good at working things out, but obviously I need to understand the correct syntax etc. I can do some things, but not most..

I'll check it out again and see if I can work it.

I did open another quesiton as it's a separate query:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_28009844.html

Thanks very much.
0
 
UName10Author Commented:
Hi Robert - got it to work here.  It's showing just '2' however for '02 minutes'.

    <div class="time">
      <div class="hour"><%=hour(rs("ca_starttime"))%></div>
      <div><%=minute(rs("ca_starttime"))%></div>
   </div> 

<div class="time">
      <div class="hour"><%=hour(rs("ca_endtime"))%></div>
      <div><%=minute(rs("ca_endtime"))%></div>
   </div> 

Open in new window


Do you know how I can change it to 24 hr format, e.g. '13:02' instead of '13 2'?

** The final '13 30' is what you provided for the non-null values just to compare, but none of them are showing the 24 hr format..

Many thanks.
0
 
Robert SchuttSoftware EngineerCommented:
Well I'll leave that question for somebody else for the moment, although they may not have a lot to go on.

I just tested it on my system and found no problem.
capture
0
 
Robert SchuttSoftware EngineerCommented:
Oops, cross posting again ;-)

Nothing but a SQL query on that link.

In general, unless you need a different styling for the hour, just put hour and minute in 1 div with a : in between.

To correct a missing 0 you can use:
<%=Right("00" & minute(rs("ca_endtime")), 2)%>

Open in new window


The final remark I don't understand.
0
 
UName10Author Commented:
It's bizarre, I don't know why it's not working.. It's ok in the database (correct format like yours), but on the page here it's just showing me '0' instead of the double '00'..

This is the code I used:

<div class="time">
      <div class="hour"><%=hour(rs("ca_starttime"))%></div>
      <div><%=minute(rs("ca_starttime"))%></div>
   </div> 

<div class="time">
      <div class="hour"><%=hour(rs("ca_endtime"))%></div>
      <div><%=minute(rs("ca_endtime"))%></div>
   </div> 

Open in new window


Really strange it won't work. Thanks a lot for checking that, much appreciated.
0
 
UName10Author Commented:
Sorry, it wasn't too clear! I used to code posted just above and it works great, just the 24 hr format at the time - but you fixed that too, thanks very much.

I'll be having them in the same div now, was just to test on separate lines...

Brilliant; thank you very much.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 10
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now