How to concat and convert date from from YYY-DD-MM to MM/DD/YYYY

I want to write a dimension with adding text values and date with MM/DD/YYYY format
eg: Result for: 2022/11/05

  dimension: resultfor {
    type: string
    sql:  'Result For : ' || ${admin_dt_date} ;;
    html:{{ rendered_value | date: "%m/%d/%Y" }};;
  }

Result is showing with the above dimenstion is like 
“Result For : 2022-11-05” But I Need “Result For : 11/05/2022”

99627a09-e538-48a6-bf2b-60b0a99b63d3.png
Result Should: “Result For : 11/05/2022”
Solved Solved
1 3 1,221
1 ACCEPTED SOLUTION

Shows error as below with the above syntax given by you…

The Amazon Redshift database encountered an error while running this query.

ERROR: column "%m/%d/%y" does not exist in table_name

----------
This is working fine>
dimension: result_for_date {      Type: string     sql: 'Result For:' || to_char(${admin_dt_date}, 'MM/DD/YYYY') ;;   }

That’s correct, you have to use the `SQL` syntax of the database engine your model is connected.

I used MySql syntax for this example.

View solution in original post

3 REPLIES 3

What about using SQL to get the result already formatted from database?

  dimension: resultfor {
    type: string
    sql:  CONCAT( 'Result For : ', DATE_FORMAT( ${admin_dt_date}, "%m/%d/%Y" )) ;;
  }

Shows error as below with the above syntax given by you…

The Amazon Redshift database encountered an error while running this query.

ERROR: column "%m/%d/%y" does not exist in table_name

----------
This is working fine>
dimension: result_for_date {      Type: string     sql: 'Result For:' || to_char(${admin_dt_date}, 'MM/DD/YYYY') ;;  

}

Shows error as below with the above syntax given by you…

The Amazon Redshift database encountered an error while running this query.

ERROR: column "%m/%d/%y" does not exist in table_name

----------
This is working fine>
dimension: result_for_date {      Type: string     sql: 'Result For:' || to_char(${admin_dt_date}, 'MM/DD/YYYY') ;;   }

That’s correct, you have to use the `SQL` syntax of the database engine your model is connected.

I used MySql syntax for this example.

Top Labels in this Space
Top Solution Authors