Skip to content

Latest commit

 

History

History
56 lines (41 loc) · 1.5 KB

File metadata and controls

56 lines (41 loc) · 1.5 KB

DateFormatTransformer

Format a date object into a string, using \DateTimeInterface::format().

Transformer reference

  • Service: CleverAge\ProcessBundle\Transformer\Date\DateFormatTransformer
  • Transformer code: date_format

Accepted inputs

  • \DateTimeInterface (\DateTime or \DateTimeImmutable)
  • Any falsy value (null, '', false…), returned unchanged

Any other value (including a date string) throws an \UnexpectedValueException. Use DateParserTransformer first to convert a string into a date.

Possible outputs

  • string: the formatted date
  • the input value itself if it is falsy

Options

Code Type Required Default Description
format string X Output format, see PHP date formats

Examples

  • Output a string like 2019-12-02
# Transformer options level
date_format:
  format: Y-m-d
  • Parse a French date and convert it to ISO 8601
# Transformer mapping level
created_at:
  code: '[date]'
  transformers:
    date_parser:
      format: d/m/Y
    date_format:
      format: 'Y-m-d\TH:i:sP'