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

FIRST date after Quarter

Status
Not open for further replies.

2009luca

Programmer
Jul 27, 2013
222
0
16
IT
consider this current Quarter 2015 (Jule 2015, august 2015, september 2015)

and myvardate="05/10/2015" (myvardate as Date)

with a code in vb6 is possible to check if myvardate is the first date after the last month in Quarter?



 
Anything is possible. You just have to define the rules.

When does your quarter start? Is it on the 1st or the first Sunday or the first Monday of every third month.
 
There are lots of intrinsic functions supporting date/time operations. These are covered very well in That Fine Manual.

Surely this will help provide a clue?

Code:
Option Explicit

Private Function Quarter(ByVal Value As Date) As Long
    'Combine year and quarter to permit easy comparisons
    '(though not arithmetic):
    Quarter = DatePart("yyyy", Value) * 10 + DatePart("q", Value)
End Function

Private Function NextQuarterBegins(ByVal Value As Date) As Date
    NextQuarterBegins = DateSerial(Year(Value), _
                                   (((DatePart("m", Value) - 1) \ 3) + 1) * 3 + 1, _
                                   1)
End Function

Private Sub Form_Load()
    Dim TestDate As Date
    
    TestDate = "May-10-2015"
    
    Text1.Text = "TestDate is " & Format$(TestDate, "mmm-dd-yyyy") & vbNewLine _
               & "Quarter(TestDate) is " & CStr(Quarter(TestDate)) & vbNewLine _
               & "Quarter(""Jul-01-2015"") is " _
               & CStr(Quarter("Jul-01-2015")) & vbNewLine _
               & "NextQuarterBegins(TestDate) is " _
               & Format$(NextQuarterBegins(TestDate), "mmm-dd-yyyy")
End Sub

Results:

Code:
TestDate is May-10-2015
Quarter(TestDate) is 20152
Quarter("Jul-01-2015") is 20153
NextQuarterBegins(TestDate) is Jul-01-2015
 
sorry me Dilettante but my date really is 05/10/2015 (five ottober 2015) and not 10/05/2015...why you use that?

in this case 05/10/2015 is really the first date based the last month in last Quarter (settember 2015 in my case)

and i think your code not help me, for now.
 
Like xwb said: "You just have to define the rules."

Fill the blanks:[pre]

Start Date End Date
1st Quarter __________ ___________
2nd Quarter __________ ___________
3rd Quarter __________ ___________
4th Quarter __________ ___________[/pre]

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.
 
>why you use that?

Dilettante lives in a region with a different date format to you.
 
Aren't DatePart and DateSerial Locale aware/independent anyway?

(genuine question; I haven't touched VB for a very long time)

Take Care

Matt
I have always wished that my computer would be as easy to use as my telephone.
My wish has come true. I no longer know how to use my telephone.
 
Sure, but the posters are not :)


2009luca: [tt]myvardate="05/10/2015"[/tt]

interpreted as

Dilettante: [tt]TestDate = "May-10-2015"[/tt]
 
Indeed, but one of those examples is unambiguous and VB will cast/coerce to a valid and expected date variable. The other can have unexpected results...

Take Care

Matt
I have always wished that my computer would be as easy to use as my telephone.
My wish has come true. I no longer know how to use my telephone.
 
If people are getting this lost over regional date formats... they probably don't qualify for membership at this site anyway. These are long-standing and long understood issues in VB and this site is only meant for professional users.

And no, plinking around with code on the job does not make you "professional" no matter how shiny your suit is or how natty your tie is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top