How to check current date lies in which quarter?

first quarter = 1st May 2022 to 1st Aug 2022
second quarter = 1st Aug to 1st Nov
third quarter = 1st Nov to 1st Feb
fourth quarter = 1st Feb to 1st May

My question is if date is for eg 6th July 2022 (date will be dynamic) it should give message as lies in First quarter
If date changes it should return their respective quarters


The following might help you.


As an alternate:
{3,4,4,4,1,1,1,2,2,2,3,3}(now.Month - 1)

with a variation:

{"First Quarter","Second Quarter", "Third Quarter", "Fourth Quarter"}({3,4,4,4,1,1,1,2,2,2,3,3}(now.Month - 1) - 1)

1 Like

this will return quarter month
but how to check in which quarter is the date for eg 6th july
date will be dynamic which is coming from GetText activity
and then i want to check gettext date lies in which quarter then proceed after


How about the following?

dateTimeVar = DateTime.Parse(System.Text.RegularExpressions.Regex.Replace(yourString.Trim,"(?<=\d+)[A-Za-z]+",""))

Sequence1.xaml (6.3 KB)


why did you regex??
i want to run this condition in loop will it work??


Because remove β€œth” of β€œ6th”.

i want to run this condition in loop will it work??

I think it’s no problem.

if date is in mm/dd/yyyy ,07/06/2022 for this regex is needed?
can you please share the steps for this it will be great


No, even if input string is β€œ07/06/2022”, it works as the following.


i am taking date as 5/1/2022 it is returning as Q4 but it should return as Q1


Sorry, I had a mistake. Please remove -1 as the following.



Is there any alternate approach without using Regex?


The following might help you.


My question is that if the date is in fixed format like β€œMM/dd/yyyy” with no (th,st,nd,rd,d) for this is there any need of Regex?
If no what will be the approach?


If input string is always β€œMM/dd/yyyy” format, simply, DateTime.Parse(yourString) will work.


A date has no format. A date is a date. If your date is in string format convert it to a valid DateTime datatype first. Use one of the many dateTime.parseExact examples.

You can then calulate a quarter relatively simple.
Divide your dateVar.moth by 3, and round the value up to an integer.
So you get:

math.ceiling(myDate.month / 3)

Resulting in:
january β†’ 1 /3 β†’ 1
february β†’ 2 /3 β†’ 1
march β†’ 3 /3 β†’ 1
april–> 4 /3 β†’ 2
november β†’ 11 /3 β†’ 4
december β†’ 12 /3 β†’ 4

After getting the desired quarter i want to use switch case but output is in string format
in switch case i need
if that value is in : Q1 then 25 data should be filled
if Q2 then 50 like that

Will i have to convert string to Int for Switch case?


Can you try to set String at typeArgument as the following?


I tried but its not going in specific cases

Then you probably use your swith activity wrongly, or your data has different outputs.

So debug and deduct:
writeline your quarter value.

  • is it a valid string?
  • does it contain one of the switch values.

Yes? your switch is wrong; no, your data is wrong.

Similary: feed your switch with a hardcoded value of Q2… does it make the right choice?

Try to break down your general issue into smaller questions makes it easy to solve most problems.