Geovisualization Developer's Guide

as_date

When you use this function in a query, it returns the values in the specified string column as date values.

For more information on using query functions and operators in a REST API request, see Queries. For an end-to-end description of how to create a query, see Creating a Query.

Take the following example dataset of geographic data and dates.

Lat;Lon;City;Population;Date;Confirmed
52.516667;13.383333;Berlin;3,562,166;31December2014;Yes
41.836944;-87.684722;Chicago;2,722,389;31July2014;Yes
39.916667;116.383333;Beijing;21,516,000;31December2014;No

The example query below converts the string values in the Date column (31December2014, 31July2014, 31December2014) into date values in the response.

{
"version": 0.3,
"dataset": "e759d63280444c3abc08b1ce72b04e48",
"namespace": {
  "as_date": {
    "source": ["Date"],
    "apply": [{
      "fn": "as_date",
      "type": "transform",
      }]
    }
  },
  "metrics": ["as_date"],
}

When you submit the above request, the response includes an HTTP status code and a JSON response body.

{
  "query": "644f5157b0574046be91a69476d8b23a",
  "kind": "datalens#query_result",
  "rows": [
        [
          "2014-12-31 00:00:00"
        ],
        [
          "2014-07-31 00:00:00"
        ],
        [
          "2014-12-31 00:00:00"
        ]
    ],
  "columns": [
    "as_date"
      ],
  "dataset": "e759d63280444c3abc08b1ce72b04e48"
}

For more information on the HTTP status codes, see HTTP Status Codes.

For more information on the elements in the JSON structure in the response body, see Query.