Cube Js | calculate difference between 2 Dates

1.2k Views Asked by At

In cube js finding the count between days is not working for mysql database. Please help me to resolve. While calculating the balance days between....

measures: {
  balanceDays: 
    {
      type: count,
      sql: DATEDIFF(day, '${NmOrder.show_date}', '${NmOrder.booked_date}')   
    },
},

This is also not working

measures: {
      balanceDays: 
        {
          type: count,
          sql: TO_DAYS(${show_date}) - TO_DAYS(${booked_date}) 
        },
    },
2

There are 2 best solutions below

0
Tech Key On BEST ANSWER

Don't need to mention MySQL keywords. Just simply like below

measures: {
      balanceDays: 
        {
          type: countDistinct,
          sql: show_date - booked_date 
        },
    },
0
halloju On

This works for me.

measures: {
      balanceDays: 
        {
          type: `number`,
          sql: `DAY(${show_date} - ${booked_date})` 
        }
    },