Text '24/07/2018 11:04' could not be parsed at index 0

My row kinda look like this

Opened_Date
25/07/2017 16:01
02/11/2017 13:49
06/11/2017 20:36
09/11/2017 18:46
13/11/2017 13:51
22/11/2017 08:26
22/11/2017 09:16
24/11/2017 09:31

I am trying to run this query

SELECT DATETIME_FORMAT(CAST(Opened_Date AS DATETIME), 'dd/MM/YYYY  HH:mm') AS opened from eta

I am getting this error

{
  "error" : {
    "root_cause" : [
      {
        "type" : "ql_illegal_argument_exception",
        "reason" : "cannot cast [24/07/2018 11:04] to [datetime]: Text '24/07/2018 11:04' could not be parsed at index 0"
      }
    ],
    "type" : "ql_illegal_argument_exception",
    "reason" : "cannot cast [24/07/2018 11:04] to [datetime]: Text '24/07/2018 11:04' could not be parsed at index 0",
    "caused_by" : {
      "type" : "date_time_parse_exception",
      "reason" : "Text '24/07/2018 11:04' could not be parsed at index 0"
    }
  },
  "status" : 500
}

This might work for you.

Query

POST /_sql
{
  "query": "SELECT DATETIME_PARSE(Opened_Date, 'dd/MM/yyyy HH:mm') AS date from eta"
}

Returns

{
  "columns" : [
    {
      "name" : "date",
      "type" : "datetime"
    }
  ],
  "rows" : [
    [
      "2017-07-25T16:01:00.000Z"
    ],
    [
      "2017-11-02T13:49:00.000Z"
    ],
    [
      "2017-11-06T20:36:00.000Z"
    ],
    [
      "2017-11-09T18:46:00.000Z"
    ],
    [
      "2017-11-13T13:51:00.000Z"
    ],
    [
      "2017-11-22T08:26:00.000Z"
    ],
    [
      "2017-11-22T09:16:00.000Z"
    ],
    [
      "2017-11-24T09:31:00.000Z"
    ]
  ]
}
2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.