Parse a string into a \DateTime, using \DateTime::createFromFormat().
- Service:
CleverAge\ProcessBundle\Transformer\Date\DateParserTransformer - Transformer code:
date_parser
string: a date matching the configuredformat\DateTime, returned unchanged\DateTimeImmutable, converted to a\DateTime(same date, time and timezone)- Any falsy value (
null,'',false…), returned unchanged
A string that cannot be parsed with the given format throws an \UnexpectedValueException.
\DateTime- the input value itself if it is falsy
| Code | Type | Required | Default | Description |
|---|---|---|---|---|
format |
string |
X | Input format, see DateTime::createFromFormat |
- Read the string
2019-12-02
# Transformer options level
date_parser:
format: Y-m-d- Read the string
02/12/2019 14:30
# Transformer options level
date_parser:
format: 'd/m/Y H:i'Fields missing from format are taken from the current time (e.g. with Y-m-d, the time part is the current time). Use
the ! or | format characters to reset them, e.g. '!Y-m-d'.