Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions reference/constraints/DateTime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ DateTime

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

+----------------+------------------------------------------------------------------------+
| Applies to | :ref:`property or method <validation-property-target>` |
+----------------+------------------------------------------------------------------------+
| Options | - `message`_ |
| Options | - `format`_ |
| | - `message`_ |
| | - `payload`_ |
+----------------+------------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\DateTime` |
Expand Down Expand Up @@ -78,6 +79,17 @@ Basic Usage
Options
-------

format
~~~~~~

**type**: ``string`` **default**: ``Y-m-d H:i:s``

.. versionadded:: 3.1
The ``format`` option was introduced in Symfony 3.1.

This option allows to validate a custom date format.
See `DateTime::createFromFormat <date_create_from_format>`_ for formatting options.

message
~~~~~~~

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

.. include:: /reference/constraints/_payload-option.rst.inc

.. _`date_create_from_format`: http://php.net/manual/en/datetime.createfromformat.php