Cognito Forms – How to Prefill Date Fields via URL

cognito-forms

I am trying to assign a value to a date type field via URL parameter to embedded form. Works fine with text fields, but can't get anything to populate the date type field. Is this possible? If so what's the trick?

?entry={"Program":"test program","GroupName":"test group","ProgramDate":"02/15/2016"}

Also tried 2016-02-15, 2016/02/15, 02-15-2016, etc

Best Answer

Prefilling your forms in Cognito Forms requires understanding the JSON format used when your entries are saved, posted to endpoints, etc. Fortunately, this format is pretty much what you would expect, with the names being the field names like you use in calculations, text values in quotes, numbers are numbers, and yes/no values are true or false.

Dates on the other hand get a bit interesting as JSON technically does not have a standardized representation for dates. However, while researching date handling for Cognito Forms, we realized that the ISO 8601 date format had become the defacto standard that everyone was using despite the lack of an official JSON standard. In the case of dates, we use just the date portion of the standard and avoid including the timezone, which avoids unexpected date shifts when viewing entries in different timezones. Similarly for times, we use the time portion without a date or timezone. And for things like the entry timestamp that are both a date and time, we use the full ISO 8601 format in the UTC timezone.

So given all of that, dates are represented as "YYYY-MM-DD" in the JSON structure for your forms. You tried this option, which should have worked, so please try this again and see if you have better luck knowing this is the correct answer.

Here is a link demonstrating date prefill using this format:

Date Prefill Example