The format-date operation converts a given date string into a specified format. This is useful when normalizing dates for APIs, reports, or user-facing outputs.
How it works
- Input – the original date as a string (e.g. 2024-02-21 15:30:00).
- Format pattern – the desired format string, based on the DateTime formatting standard.
- Result – the date reformatted according to the pattern. If the input cannot be parsed as a valid date, the original value is returned unchanged.
Examples
Input | Format Pattern | Output |
---|---|---|
2024-02-21 | d.m.Y | 21.02.2024 |
2024-02-21 15:30:00 | Y-m-d H:i | 2024-02-21 15:30 |
invalid date | d.m.Y | invalid date |
Common Format Patterns
- Y-m-d → 2024-02-21 (ISO format)
- d.m.Y → 21.02.2024 (European style)
- m/d/Y → 02/21/2024 (US style)
- Y-m-d H:i:s → 2024-02-21 15:30:00 (full timestamp)
- l, j F Y → Wednesday, 21 February 2024 (long text form)
Usage in PalDock
Use format-date when you need to:
- Convert system-generated dates into the format required by an external API.
- Display user-friendly date formats in outputs.
- Standardize dates for reporting and exports.
- Strip time information (e.g. from Y-m-d H:i:s to Y-m-d).
⚠️ Always put the prefix “@” before the date format.
Best Practices
- Always use clear and unambiguous formats when passing dates between systems.
- Be mindful of time zones – format-date only reformats the string, it does not adjust the timezone unless combined with other operations.
- Validate date strings before formatting to avoid passing invalid data.
- Stick to ISO 8601 (Y-m-d H:i:s) for machine-to-machine integrations, unless the external system specifies otherwise.