first date after the last month in quarter

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

first date after the last month in quarter

Post by sal21 »

admit have myvardate=05/10/2015

i need to check if is the first helpful date after the last month in the current quarter. in my case 05/10/2015 is thrue.
Possible?

in my case is settember the last month in current quarter.



or for example 08/01/2016 is the first helpful date after the last month in quarter ottober, november dicember

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

Re: first date after the last month in quarter

Post by HansV »

What is a "helpful" date?
Best wishes,
Hans

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

Re: first date after the last month in quarter

Post by sal21 »

HansV wrote:What is a "helpful" date?
Narest...

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

Re: first date after the last month in quarter

Post by HansV »

I'm sorry, I don't understand what you want. Can you try to explain it more clearly?
Best wishes,
Hans

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

Re: first date after the last month in quarter

Post by sal21 »

HansV wrote:I'm sorry, I don't understand what you want. Can you try to explain it more clearly?
In effett i need to start to the end of each quarter my macro code.
That is all

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

Re: first date after the last month in quarter

Post by HansV »

But why would the result be 08/01/2016 is the quarter is October/November/December?
Best wishes,
Hans

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

Re: first date after the last month in quarter

Post by sal21 »

HansV wrote:But why would the result be 08/01/2016 is the quarter is October/November/December?
dont consider this... :thumbup:

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

Re: first date after the last month in quarter

Post by HansV »

Does this do what you want?

Dim newDate As Date
newDate = DateSerial(Year(myvardate), 3 * ((Month(myvardate) - 1) \ 3) + 4, 1)
Best wishes,
Hans

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

Re: first date after the last month in quarter

Post by sal21 »

HansV wrote:Does this do what you want?

Dim newDate As Date
newDate = DateSerial(Year(myvardate), 3 * ((Month(myvardate) - 1) \ 3) + 4, 1)

hummmm....

I propose again my condition in pseudo code:

is 08/10/2015 the first date after the last day in elapsed Quarter?

last day in elapsed Quarter is 30/09/2015, 08/10/2015 is the first date near...

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

Re: first date after the last month in quarter

Post by HansV »

Sorry, I don't understand that. Why is 08/10/2015 the first date after 30/09/2015?
Best wishes,
Hans

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

Re: first date after the last month in quarter

Post by sal21 »

HansV wrote:Sorry, I don't understand that. Why is 08/10/2015 the first date after 30/09/2015?
I run a code each day and i need the check function each day.
08 october is day now

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

Re: first date after the last month in quarter

Post by HansV »

The current date is always later than the end of the previous quarter, by definition.
Best wishes,
Hans

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

Re: first date after the last month in quarter

Post by sal21 »

HansV wrote:The current date is always later than the end of the previous quarter, by definition.

study on Quarter

this function return steep of Quarter, but i see return in a last date one day -1!!!!


Dim anno As Integer, I As Integer

anno = 2015

For I = 1 To 4
Debug.Print I & "Q - DAL: " & Format(DateSerial(anno, (I - 1) * 3 + 1, 1), "dd/mm/yyyy") _
& " AL: " & Format(DateSerial(anno, I * 3 + 1, -1), "dd/mm/yyyy")

Next

in debug.print, have:

1Q - Da: 01/01/2015 A: 30/03/2015<31/03/2015
2Q - Da: 01/04/2015 A: 29/06/2015<30/06/2015
3Q - Da: 01/07/2015 A: 29/09/2015<30/09/2015
4Q - Da: 01/10/2015 A: 30/12/2015<31/12/2015

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

Re: first date after the last month in quarter

Post by HansV »

The solution is very simple: use 0 instead of -1:

Debug.Print I & "Q - DAL: " & Format(DateSerial(anno, (I - 1) * 3 + 1, 1), "dd/mm/yyyy") _
& " AL: " & Format(DateSerial(anno, I * 3 + 1, 0), "dd/mm/yyyy")
Best wishes,
Hans

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: first date after the last month in quarter

Post by macropod »

Cross-posted at: http://www.tek-tips.com/viewthread.cfm?qid=1755999" onclick="window.open(this.href);return false;
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184" onclick="window.open(this.href);return false;
Paul Edstein
[Fmr MS MVP - Word]