Search code examples
pythonregexgrafanainfluxdb

how to get dates sorted in ascending order from influx db query, right now its in string format


I have a query

SELECT last("date_of_maturity") FROM "maturity_date_data" GROUP BY "maturity";

Im getting this values

010423
020423
070423
140423
260523
280423
290923
291223
300623
310323

The field is string format, but the values are dates. Need output arranged datewise.


Solution

  • You could to convert your string date to actual date, and order by it:

    SELECT last("date_of_maturity") dom
      FROM "maturity_date_data"
     GROUP BY "maturity";
     ORDER BY to_date(dom, 'ddMMyy') asc