How can I change period to format date?

Hi

I have period date compose by 6 numbers, the first four numbers it’s the year and the last two is the month, example: yyyymm. (202201 )

The problem with this field is that sometimes changes between int and string. How can I change everything to a date format? dd/MM/yyyy

First you would always cast to a string.

toString(date)

Then you would need to change this into a supported date format.

concat(substring(toString(date),1,4),‘/’,substring(toString(date),5,7),‘/’,‘01’)

Finally you would parse this as a date.

parseDate(concat(substring(toString(date),1,4),‘/’,substring(toString(date),5,7),‘/’,‘01’),‘yyyy/MM/dd’)

This would be the final calculated field ^

Let me know if that helps.

1 Like

Hi max!

Thanks for this solution!, I only need to correct this thing in the function

parseDate(concat(substring(toString(date),1,4),‘/’,substring(toString(date),5,2),‘/’,‘01’),‘yyyy/MM/dd’)

1 Like