×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

hour and minutes inrterval step 30 minutes
3

hour and minutes inrterval step 30 minutes

hour and minutes inrterval step 30 minutes

(OP)
Dim DA As Date, A As Date

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

RE: hour and minutes inrterval step 30 minutes

What have you tried so far?
Show some code of your attempts.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: hour and minutes inrterval step 30 minutes

(OP)

CODE

Dim D As Date
    For D = DA To A Step 30
        Debug.Print D
    Next D 

but dont work2thumbsup

RE: hour and minutes inrterval step 30 minutes

One way:

CODE

Call ShowTimes("7:00", "9:00", 30) 

CODE

Private Sub ShowTimes(ByRef StartTime As String, ByRef StopTime As String, ByRef Interval As Integer)
Dim dtStop As Date
Dim dt As Date

dt = CDate(StartTime)
dtStop = CDate(StopTime)

Debug.Print dt

Do While dt <= dtStop
    dt = DateAdd("n", Interval, dt)
    If dt > dtStop Then Exit Do
    Debug.Print dt
Loop

End Sub 

output:
7:00:00 AM 
7:30:00 AM 
8:00:00 AM 
8:30:00 AM 
9:00:00 AM  

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: hour and minutes inrterval step 30 minutes

(OP)
ops....
but i required to redim DA and A in As String, or not?

RE: hour and minutes inrterval step 30 minutes

I don't know what you mean by "redim DA and A in As String"

Date (and Time) is just a Number, so you can add to it or subtract from it.
You cannot add or subtract any value(s) from Strings. You can (kind of) "add" - concatenate - to a String, but not 'add' as math adding.

If you just add a number to a Date, you are adding Days (not minutes, or seconds, or whatever):

CODE

Dim DA As Date, A As Date
Dim D As Long

DA = Date
A = Date + 120

For D = DA To A Step 30
    Debug.Print CDate(D)
Next D 

Today, from above code you get as an output in 30 days increments:
3/28/2022 
4/27/2022 
5/27/2022 
6/26/2022 
7/26/2022 
 

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: hour and minutes inrterval step 30 minutes

If working with date type:

CODE -->

Dim DA As Date, A As Date, D As Date
DA = TimeSerial(7, 0, 0)
A = TimeSerial(9, 30, 0)
For D = DA To A Step (1 / 48)
    Debug.Print D
Next D 

combo

RE: hour and minutes inrterval step 30 minutes

>but i required to redim DA and A in As String, or not?

No, not necessarily - you could just modify the procedure definition

Private Sub ShowTimes(ByRef StartTime As Date, ByRef StopTime As Date, ByRef Interval As Integer)


But as you can see - there are many ways to skin this particular cat ...

RE: hour and minutes inrterval step 30 minutes

(OP)
WOW!
tks to the all.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close