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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrive all month> the current month and year

Status
Not open for further replies.

2009luca

Programmer
Jul 27, 2013
222
IT
I jest have a Date var=set 2015.
Based this var i need to retrive all other month> of set 2015 in the same 2015.

example:var=set 2015
ott 2015
nov 2015
dic 2015

example:var=mar 2015
apr 2015
mag 2015
gu 2015
lug 2015
ago 2015
set 2015
ott 2015
nov 2015
dic 2015
 
Your "Date var" is not a Date, since it holds 2015 (number?, integer? string?) or 'mar 2015' (string)

How about this, you pass an actual date:

Code:
Option Explicit

Private Sub Command1_Click()

Call MyDates(CDate("05/12/2015"))

End Sub

Private Sub MyDates(ByRef datDate As Date)
Dim intM As Integer

If Month(datDate) = 12 Then Exit Sub

For intM = Month(datDate) + 1 To 12
    MsgBox Format(CDate(intM & "/01/" & Year(datDate)), "mmm yyyy")
Next intM

End Sub

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
@2009luca, as a programmer, surely you know that dates are not strings. At a minimum, your string ought to lead with year and also use numeric characters for month rather than alpha, which I am certain that you realize as a programmer, that alpha months will not collate as expected.

But I agree with Andy: use actual dates!
 
So to do what you want, i.e.: "retrive all month[s that are grater than] the current month and year" you may just :
[tt]
Call MyDates([blue]Date[/blue])
[/tt]
Which will give you:
[tt]Mar 2015
Apr 2015
May 2015
Jun 2015
Jul 2015
Aug 2015
Sep 2015
Oct 2015
Nov 2015
Dec 2015[/tt]

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Andrzejek, YES I NEED EXACTLLY WATH YOU POST!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top