Geovisualization Developer's Guide

date_trunc

When you use this function in a query, it truncates the dates of the time unit in the specified column in the specified dataset based on the value specified in the parameter params. For instance, if you specify month, then this date function returns the first day of the month. If you specify year, then this date function returns the first day of the year. If you specify week, this date function returns the first day of the week.

The allowed values are as follows:
  • second
  • minute
  • hour
  • day
  • dayofweek
  • dayofyear
  • week
  • month
  • year
  • quarter
  • decade

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.

The codeblock example below calculates the first day of the month for the entries in the Datetime column of the earthquake dataset, whose {DATASET_ID} is 90af668484394fa782cc103409cafe39.

{
  "version": 0.3,
  "dataset": "90af668484394fa782cc103409cafe39",
  "namespace": {
    "date_truncation": {
      "source": ["datetime"],
      "apply": [{
        "fn": "date_trunc", 
        "type": "transform",   
        "params": ["month"]
      }]
    }
  },  
  "metrics": ["date_truncation"],
}

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

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.