How to customize date format
Users often ask “why is the date field not being filled when all other fields are filled in correctly?” or “how can the date format be changed?”. If you’re having difficulties filling in the date field on your PDF form then this tutorial is for you.
Why is the date field not being filled?
A likely reason for PDF fields not getting filled is that the data format is incorrect. The solution is to change the CF7 field’s date format to match the PDF field’s format. See the date format conversion table for reference.
You may also notice that the date field of your PDF form is filled in the format YYYY-MM-DD
(e.g. 2022-06-30) even if the PDF file specifies a different format. This is because the YYYY-MM-DD
format conforms to the HTML5 specification, and often the browser’s date picker UI sets the value in this format by default.
How can the date format be changed?
To change the date format, you need to use the [_format_{field name} "format date"]
tag. The following example demonstrates how it can be done:
- Create a CF7 form-tag for the date field and map it to the corresponding PDF field. For more information on how to create form-tags and map fields, please see the creating a form-tag guide.
Image 1
- Find your date field in the Field Mapper Tool and convert it to mail-tag by clicking the pencil icon.
Image 2
- Change the tag to match the following pattern:
[_format_{field name} "date format"]
. Replace{field name}
with the name of your field, which isdob
. Replacedate format
with the desired date format, based on the CF7 format column in the date format conversion table. In our example, it isd-m-Y
. See more details in the CF7 documentation.
Image 3
Date format conversion table
The CF7 date format is equivalent to the PHP date format, while the PDF date format uses a different scheme.
The following table can be used for the conversion of PDF date format strings to CF7 date format strings for use in [_format_form-tag "format-string"]
mail-tag.
CF7 | Example | |
---|---|---|
m/d | n/j | 6/27 |
m/d/yy | n/j/y | 6/27/22 |
mm/dd/yy | m/d/y | 06/27/22 |
mm/yy | m/y | 06/22 |
d-mmm | n-M | 6-Jun |
d-mmm-yy | n-M-y | 6-Jun-22 |
dd-mmm-yy | d-M-y | 27-Jun-22 |
dd/mm/yy | d/m/y | 27/06/22 |
dd/mm/yyyy | d/m/Y | 27/06/2022 |
dd.mm.yyyy | d.m.Y | 27.06.2022 |
yy-mm-dd | y-m-d | 22-06-27 |
mmm-yy | M-y | Jun-22 |
mmmm-yy | F-y | June-22 |
mmm d, yyyy | M j, Y | Jun 27, 2022 |
mmmm d, yyyy | F j, Y | June 27, 2022 |
m/d/yy h:MM tt | n/j/y g:i a | 6/27/22 1:24 pm |
m/d/yy HH:MM | n/j/y H:i | 6/27/22 13:25 |
yyyy-mm-dd | Y-m-j | 2022-06-27 |