Help with a Time array

H

Hans

Hi there, I need to create a list (diary style) of times in a day. I can do
this with normal "metricated" break-up of the hours, but need to display the
actual time.

I have a "Starting time" and an ending time as variables. I also have a
"Timespan" for the increment.
For example Start time=8:00 AM
End Time 6:00 PM and increment in 30 minute intervals

I need to convert anything after the decimal point into Minutes. If I have
"11.5" I want to show it as "11.30". I can divide the decimal into 60 to
give me the Minute equivalent of the decimal, but need to do this without
affecting the "Hour"
The start time, end time and increments will be a variable from a database.
Any help will be much appreciated.

Thanks
Hans
 
A

Alex Goodey

If the variable is a string eg. "11.5" you could use string manipulation
i.e. Left(), Right(), indexOf() to find the certain parts of the value. then
make the calculations on the relevant parts and concatenate the two strings,
to display the time.
 
H

Hans

Thanks Alex,

Not too sure what you mean here, I am testing it with a form to see if it
works OK, the code is as follows:


<%
AppTime=60
If Request("App_Time")<>"" then
AppTime =Request("App_Time")
end if
AppBrk=AppTime/60

AppStart=9
If Request("StartTime")<>"" then
AppStart =Request("StartTime")
end if
AppEnd=6
If Request.Form("End_Time")<>"" then
AppEnd =Request.Form("End_Time")
end if
%>

<%
hourCounter = AppStart
Do WHILE hourCounter < 12 %>

Hours: <%Response.Write(hourCounter)%> - AM<br>
<% hourCounter = hourCounter + AppBrk
Loop
%>
<%
PMCounter = 0
Do WHILE PMCounter <= AppEnd-AppBrk %>

Hours:
<% If PMCounter<1 Then
Response.Write (PMCounter+12)
else Response.Write(PMCounter)
end if%> - PM<br>
<% PMCounter = PMCounter + AppBrk
Loop
%>

How would I use your suggestion?

Thanks

Hans
 
A

Alex Goodey

Try this, oh and i meant the InStr() function not indexOf()

<%
AppTime=60
If Request("App_Time")<>"" then
AppTime =Request("App_Time")
end if
AppBrk=AppTime/60

AppStart=9
If Request("StartTime")<>"" then
AppStart =Request("StartTime")
end if
AppEnd=6
If Request.Form("End_Time")<>"" then
AppEnd =Request.Form("End_Time")
end if
%>

<%
hourCounter = AppStart
AppBrk = 0.5
Do WHILE hourCounter < 12 %>

Hours:
<%
intPosDot = inStr(hourCounter, ".")
if intPosDot = 0 then
Response.Write(hourCounter)
else
strHour = Left(hourCounter, intPosDot-1)
strMinute = Right(hourCounter, len(hourCounter)-intPosDot)
strMinute = "0." & strMinute
strMinute = 60 * strMinute
Response.Write(strHour & ":" & strMinute)
end if

%>

- AM<br>
<% hourCounter = hourCounter + AppBrk
Loop
%>
<%
PMCounter = 0
Do WHILE PMCounter <= AppEnd-AppBrk %>

Hours:
<% If PMCounter<1 Then
intPosDot = inStr(PMCounter, ".")
if intPosDot = 0 then
Response.Write (PMCounter+12)
else
strHour = Left(PMCounter, intPosDot-1)
strMinute = Right(PMCounter, len(PMCounter)-intPosDot)
strMinute = "0." & strMinute
strMinute = 60 * strMinute
Response.Write(strHour & ":" & strMinute)
end if
else
intPosDot = inStr(PMCounter, ".")
if intPosDot = 0 then
Response.Write(PMCounter)
else
strHour = Left(PMCounter, intPosDot-1)
strMinute = Right(PMCounter, len(PMCounter)-intPosDot)
strMinute = "0." & strMinute
strMinute = 60 * strMinute
Response.Write(strHour & ":" & strMinute)
end if
end if%> - PM<br>
<% PMCounter = PMCounter + AppBrk
Loop
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top