Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Challenges with Interval() format & translation/internationalization (pt-BR)

Hi all!

The problem: get an interval and translate it to another language, my case is portuguese (pt-BR).

Documentation reference:

Let's say:

timestamp_0 = 20/07/2018 15:00:00

timestamp_1 = 21/07/2018 17:00:00

// note the 24H pattern

I need to get "1 dia 02 horas", this is pt-BR translation for  "1 day 02 hours";

Try 1:

Interval(timestamp_0 - timestamp_1, 'D hh')

// obviously it shows "1 02" as expected, ok

Try 2:

// getting days

Interval(timestamp_1 - timestamp_0, 'D')

  // solving plurals

  & If(Interval(timestamp_1 - timestamp_0, 'D') > 1, ' dias', ' dia')

// getting hours

& Interval(timestamp_1 - timestamp_0, 'hh')

  // solving plurals

  & If(Interval(timestamp_1 - timestamp_0, 'hh') > 1, ' horas', ' hora')

// It shows "1 dias 26 horas", so not as expected, and I didn't understood why I got "dias" instead of "dia"... so

Try 3 (fancy and lazy way):

Replace(Interval(timestamp_1 - timestamp_0, 'D hh') , ' ', 'd ') & 'h'

// shows "1d 02h", it is ok for pt-BR, en-US and many other languages

So, to get "1 dia 02 horas" I can implement a tedious and ugly code with many "replaces" and "Ifs". Not so fun.

Is there a smartest way to do that?

Thanks a lot.

Best regards.

P.S.: is there a way to put

 in this editor? I mean, like Github or PhpBB fórums, etc.? It would be nice too.

1 Reply
fernando_tonial
Partner - Specialist
Partner - Specialist

Hi, you can try this.

=SubField(Interval(timestamp_1 - timestamp_0, 'D hh'),' ',1)

  // solving plurals

& If(SubField(Interval(timestamp_1 - timestamp_0, 'D hh'),' ',1) > 1, ' dias ', ' dia ')

// getting hours

& SubField(Interval(timestamp_1 - timestamp_0, 'D hh'),' ',2)

// solving plurals

& If(SubField(Interval(timestamp_1 - timestamp_0, 'D hh'),' ',2) > 1, ' horas', ' hora')

Result.

1 dia 02 horas

Don't worry, be Qlik.

Tonial.

Don't Worry, be Qlik.