Skip to content

Commit f8d1e82

Browse files
committed
Added docs about the format option
1 parent 1f4113f commit f8d1e82

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

reference/constraints/DateTime.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ DateTime
33

44
Validates that a value is a valid "datetime", meaning either a ``DateTime``
55
object or a string (or an object that can be cast into a string) that follows
6-
a valid YYYY-MM-DD HH:MM:SS format.
6+
a specific format.
77

88
+----------------+------------------------------------------------------------------------+
99
| Applies to | :ref:`property or method <validation-property-target>` |
1010
+----------------+------------------------------------------------------------------------+
11-
| Options | - `message`_ |
11+
| Options | - `format`_ |
12+
| | - `message`_ |
1213
| | - `payload`_ |
1314
+----------------+------------------------------------------------------------------------+
1415
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\DateTime` |
@@ -78,6 +79,17 @@ Basic Usage
7879
Options
7980
-------
8081

82+
format
83+
~~~~~~
84+
85+
**type**: ``string`` **default**: ``Y-m-d H:i:s``
86+
87+
.. versionadded:: 3.1
88+
The ``format`` option was introduced in Symfony 3.1.
89+
90+
This option allows to validate a custom date format.
91+
See `DateTime::createFromFormat <date_create_from_format>`_ for formatting options.
92+
8193
message
8294
~~~~~~~
8395

@@ -86,3 +98,5 @@ message
8698
This message is shown if the underlying data is not a valid datetime.
8799

88100
.. include:: /reference/constraints/_payload-option.rst.inc
101+
102+
.. _`date_create_from_format`: http://php.net/manual/en/datetime.createfromformat.php

0 commit comments

Comments
 (0)