Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looping days in month-year 1

Status
Not open for further replies.

2009luca

Programmer
Jul 27, 2013
222
IT
I just have a myvar="02-2018" (month-year)

How to loop all days in this period?

Tks.
 
The simplest way is to convert to date, and loop on the date, like this.

Code:
    Dim myVar As String
    Dim StartDate As Date
    Dim EndDate As Date
    Dim ThisDate As Date
    
    myVar = "02-2018"
    
    StartDate = CDate(myVar)
    EndDate = DateAdd("d", -1, DateAdd("m", 1, StartDate))
    

    For ThisDate = StartDate To EndDate
        Debug.Print ThisDate
    Next

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
hI George,
tks from Italy...
Exactlly what I needed!
Nice code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top