Using the time period parameter to specify dynamic dates for weather API history requests

Sometimes when requesting historical weather data via the weather API we wish to request data for a fixed period based on the current data. For example, request the data for yesterday or today.

The time period parameter of the weather API allows you to easily request data for dynamic time periods.

Example request

Here is an example of using the period parameter in a sentence:

http://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/weatherdata/history?&aggregateHours=24&period=yesterday&contentType=csv&unitGroup=us&locationMode=single&key=YOUR_KEY&locations=Reston%2C%20VA%2C%20US 

The period parameter is a replacement for the startDateTime and endDateTime parameters – the system calculates the values for those parameters for you. When a period is specified, it is not possible to specify the startDateTime and endDateTime in the same query.

The period is applicable to any request aggregation level including daily, hourly and sub-hourly requests. Note that the time period names are case sensitive and must be specified in lower case.

Just as with the startDateTime and endDateTime parameters, the dynamic start and end date times are used based on the local time of the locations being queried.

Available time periods

The API currently supports the following time periods.

today – from midnight to the current time on the current date time.

yesterday – from midnight to midnight on yesterday’s date.

yeartodate – from midnight of January 1st of the current year until the current date time.

monthtodate– from midnight on the 1st of the current month until the current date time.

Need more dynamic periods?

Please contact us to request additional dynamic date time periods.

Leave a Reply

Your email address will not be published. Required fields are marked *