How to get first month of previous quarter

Hello!
I have a question and I really hope you can help me. I don’t find a solution by my own

I need the first month of the last quarter (“yyyy.MM”). For example:
Today is 18th March 21 → 2020.10
Today is 31st Dec 20 → 2020.07
Today is 23rd Sep 20 → 2020.04

Do you have any ideas?
Thanks,
Ani

@Ani_Ma - Please take a look here for the logic…From this, you can get the month instead of date…

@Ani_Ma
have a look here:

test result:

In case of the Strings 31st Dec 20… are to handle, then we write some cleansing job removing st,nd, rd and can parse the date string as usually e.g. with DateTime.ParseExact(… method

In case of a more dynamic going back is needed we can do as well

Hi,

Another solution :

First, make the following dictionary.

``````dict = new Dictionary(Of Int32, Int32())From{{1,{10,-1}},{2,{10,-1}},{3,{10,-1}},{4,{1,0}},{5,{1,0}},{6,{1,0}},{7,{4,0}},{8,{4,0}},{9,{4,0}},{10,{7,0}},{11,{7,0}},{12,{7,-0}}}
``````

Let’s say dateVar as target date var.

Then

``````(dateVar.Year+dict(dateVar.Month)(1)).ToString+"."+dict(dateVar.Month)(0).ToString
``````

Main.xaml (5.7 KB)

Regards,

2 Likes

If that is based on today date, the amounts of months would change. In April it would be 3.

So it can do sth like this

Int_month = today.Month

Switch with integers (1-12)

etc.

After that:

Other way:

Int_month = today.Month

If int_month mod 3 =0
Else
If int_month mod 3 = 2
Then
Else

Quarterly starting months are standard aren’t they? Shouldn’t we be simply looking at which bracket a current month falls into and take the starting month of that bracket?

If Month (Today) between 1 and 3 then
Q1_Date = Jan 1, 2021
Else if
Blah …

End if

Or is this too simple? Because you can then extend this pseudo-code to get 1st Month of current, past or present quarter?

Thank you all for your replies!
Based on the link from @prasath17 I found a solution: