Choose quarter based on current date

Hi team

I want to write quarter start date and quarter end date based on the current date
Q1: 1 January, 2022 to 31 March, 2022
Q2: 1 April, 2022 to 30 June, 2022
Q3: 1 July, 2022 to 30 September, 2022
Q4: 1 October, 2022 to 31 December, 2022

so if the current date is 4 February, 2022, it should give me Q1 start and end date,
So how can i automate it and keeping the year as current year inorder to make it dynamic.

1 Like


Have a view on this


Hi @Aishwarya_Bhargava,

have a look on the below thread -


Hi @Aishwarya_Bhargava

You can calculate the quarter by:

quarter = (someDate.Month - 1) \ 3 + 1

Following best practices, you can separate it into two different components.

1. Calculating the quarter:
Create a function (workflow) with arguments in_dtDate as DateTime and out_intQuarter
Assign out_Quarter to (in_dtDate.Month - 1) \ 3 + 1

2. Returning the start and end date
Create a function (workflow) which accepts in_intQuarter and out_strQuarterDates
Create a switch statement of 1-4, which sets assigns out_strQuarterDates to the strings you listed.

Invoke both workflows from the component you need it from. If you want to pass the current date into the first component, use DateTime.Now.

Kind Regards


“Q” & Math.Ceiling(YourDateTimeVar.Month / 3).ToString

Hi @Aishwarya_Bhargava ,

Take a Look at the below Code Snippet :

Let’s assume the input date is in String format stored in InputDateStr, then you would need to convert it to DateTime format first, else you could directly assign the Date value to InputDate.

InputDate = DateTime.ParseExact(yourDateStr,"dd MMMM, yyyy",System.Globalization.CultureInfo.InvariantCulture);

currQuarter = Cint((InputDate.Month - 1) / 3) + 1;

dtFirstDay = new DateTime(InputDate.Year, 3 * currQuarter - 2, 1);

dtLastDay = new DateTime(InputDate.Year, 3 * currQuarter + 1, 1).AddDays(-1);

Where currQuarter is an Integer variable, which holds the Quarter number, dtFirstDay and dtLastDay are the First and Last days of the quarter found.

Let us know if this doesn’t work.


it worked
Thankyou :slight_smile:


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.