ALTERYX INSPIRE | Join us this May for for a multi-day virtual analytics + data science experience like no other! Register Now
alteryx Community

# Alteryx Designer Discussions

SOLVED

## Date to Quarter and Year 7 - Meteor

I have a date column 1/1/2017 that I need to convert to quarter and year 1Q 2017. What is the best way to do that?  17 - Castor

Probably not the best way to go about this, but I don't think there are any 'quarter' capabilities with alteryx's default date time tools (though James Dunkerlys add on may have this level of detail in).

The following formula should suffice (presuming your date is in the format MM/DD/YYYY)

IF

tonumber(left([datefield],findstring([datefield],"/"))) < 4 then "1Q "

elseif

tonumber(left([datefield],findstring([datefield],"/"))) < 7 then "2Q "

elseif

tonumber(left([datefield],findstring([datefield],"/"))) < 10 then "3Q "

else "4Q "

endif

+ Right([datefield],4)

and if your date format is dd/mm/yyyy then the following should do...

IF

tonumber(substring([datefield],findstring([datefield],"/")+1,findstring(right([datefield],length([datefield])-(findstring([datefield],"/")+1)),"/"))) < 4 then "1Q "

elseif

tonumber(substring([datefield],findstring([datefield],"/")+1,findstring(right([datefield],length([datefield])-(findstring([datefield],"/")+1)),"/"))) < 7 then "2Q "

elseif

tonumber(substring([datefield],findstring([datefield],"/")+1,findstring(right([datefield],length([datefield])-(findstring([datefield],"/")+1)),"/"))) < 10 then "3Q "

else "4Q "

endif

+ Right([datefield],4)

See the attached workflow to see how I have implemented these.

Regards,
Ben 7 - Meteor

Thanks Ben,

Worked like a charm. Big help. 6 - Meteoroid

What would this formula look like if my date is in this format yyyy-mm-dd? 5 - Atom

Hi,

this should work if [date] is a Date-Type:

"Q" + ToString(
CEIL(DateTimeMonth([Date])/3)
)

+ " " + ToString(DateTimeYear([Date])) 5 - Atom

Thanks so much for this string/formula - worked perfectly!

Labels