Make a loop with time

# Thread: Make a loop with time

1. Senior Member
Join Date
Dec 1969
Posts
384

## Make a loop with time

Hello.<BR>i have a question about loop and time.<BR><BR>this is a very simple Loop<BR><BR>&#060;% Dim LoopNr, Raknare<BR>For LoopNr = 1 To 10 Step 2<BR><BR>Raknare = Raknare + LoopNr<BR><BR>Response.Write Raknare<BR><BR>Next<BR>%&#062;<BR><BR>is it possible to make a Loop like this but use Time instead,<BR>what i mean is something like this<BR><BR>For LoopNr = 08:00 To 19:00 Step 30min<BR><BR>is this possible in any way?<BR><BR>Thanks

2. Senior Member
Join Date
Dec 1969
Posts
224

## RE: Make a loop with time

3. Senior Member
Join Date
Dec 1969
Posts
384

## RE: Make a loop with time

you mean to make that loop?

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Sure...not hard...

A couple of ways. Easiest:<BR><BR>&#060;%<BR>startTime = TimeSerial( 8, 0, 0 ) &#039; 8:00:00<BR>endTime = TimeSerial( 19, 0, 0 ) &#039; 19:00:00<BR><BR>curTime = startTime<BR>Do Until curTime &#062;= endTime<BR> Response.Write curTime<BR> ...<BR> curTime = DateAdd( "n", 30, curTime )<BR>Loop<BR>%&#062;<BR><BR>Or you could do it based on minutes:<BR><BR>&#060;%<BR>For minutes = 8*60 To 19*60 Step 30<BR> curTime = TimeSerial( 0, minutes, 0 )<BR> Response.Write curTime<BR> ...<BR>Next<BR>%&#062;<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Thorpe thought you meant...

...that you wanted to have a loop that did nothing but just kept running from 0800 to 1900. In other words, an 11 hour "do nothing" loop.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
384

## RE: Sure...not hard...

Thanks for the fast and good answer.<BR><BR>By the way, do the format have to be hh:mm:ss i would like to not have the seconds.<BR><BR>i have the same problem when i take info from access db, even that i use short format time/date in the db it look right without the seconds, but when i put it from db to page then he adds the seconds.

7. Senior Member
Join Date
Dec 1969
Posts
384

## RE: Thorpe thought you meant...

aahhh then i understand what he ment.

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## You can use a RegularExpression...

...to get rid of the seconds, but since you want 24-hour time I&#039;d just use brute force:<BR><BR>&#060;%<BR>Function HHMM( tm )<BR> HHMM = Right( "0" & Hour(tm), 2 ) & ":" & Right( "0" & Minute(tm), 2 )<BR>End Function<BR>%&#062;<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
384

## RE: You can use a RegularExpression...

Okey, thanks.<BR><BR>is it hard to input this one in the Loop code you gave me before?

10. Senior Member
Join Date
Dec 1969
Posts
96,118

## Just put the function...

...at the TOP of your ASP page any place.<BR><BR>And then just invoke the function from inside the loop:<BR><BR>&#060;% <BR>For minutes = 8*60 To 19*60 Step 30 <BR> curTime = TimeSerial( 0, minutes, 0 ) <BR> Response.Write HHMM( curTime )<BR> ... <BR>Next <BR>%&#062; <BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•