STEP hour and minutes

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

STEP hour and minutes

Post by sal21 »

I just have tghis var

...
Dim DA As Date, A As Date

DA = Format(RS.Fields(0).Value, "HH:MM")
A = Format(RS.Fields(1).Value, "HH:MM")
...

for example:

DA=07:00
A=09:30

How to create a list oh time with a step of 30 minutes

to the and i need

07:00
07:30
08:00
08:30
09:00
09:30

NOTE:
if my setting o var are wrong other way are welcome
the filed are setting with data breve

User avatar
HansV
Administrator
Posts: 78457
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: STEP hour and minutes

Post by HansV »

Code: Select all

    Dim D As Date
    For D = DA To A Step TimeSerial(0, 30, 0)
        ' Do something with the value of D, for example:
        Debug.Print D
    Next D
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

Re: STEP hour and minutes

Post by sal21 »

HansV wrote:
28 Mar 2022, 11:00

Code: Select all

    Dim D As Date
    For D = DA To A Step TimeSerial(0, 30, 0)
        ' Do something with the value of D, for example:
        Debug.Print D
    Next D
HUMMM...

for DA=19:00 and A=21:30

the loop stop to 21:00, possible

User avatar
HansV
Administrator
Posts: 78457
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: STEP hour and minutes

Post by HansV »

This is due to rounding errors. As a workaround:

Code: Select all

    Dim D As Date
    For D = DA To A + 0.000001 Step TimeSerial(0, 30, 0)
        Debug.Print D
    Next D
Best wishes,
Hans