cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Quarter formula

nvinay091
Deputy Chef I
Deputy Chef I

How to get which quarter from the date format 2022-01-31
Is there any formula to get, quarters ( Q1, Q2, Q3,Q4) from the date

6 REPLIES 6

vinny-sosa
Deputy Chef I
Deputy Chef I
Not that I am aware of. Though you may consider using a function to calculate it. Use logger to test and replace "date" with whatever variable you want to use to determine the quarter. You may use now for that as well... see below. If your quarters line up differently to months, edit the below however you see fit.

date.strftime("%mm").match?(01|02|03) ? "q1" :
date.strftime("%mm").match?(04|05|06) ? "q2" :
date.strftime("%mm").match?(07|08|09) ? "q3" :
date.strftime("%mm").match?(10|11|12) ? "q4" :
""




max-knutsson
Workato employee
Workato employee

Looks like the quarter is not a Ruby default method, so the way we can do this is use one of the code connectors like JavaScript. Here is an example how it will look like. Given the input_date is the date you want to calculate quarter for (or you can just type today in formula. We return quarter as output.


1. add JavaScript connector

2. Create input called input_date with type date

3. create output quarter of type integer

4. add this code snippet:

exports.main = ({input_date}) => {

var today = new Date(input_date)

var quarter = Math.floor((today.getMonth() + 3) / 3);

return { quarter };

}