Skip to main content
Laravel Data provides flexible date handling with support for multiple formats, timezones, and date types.

Default Date Format

Configure the default format in config/data.php:
Use with DateTimeInterfaceCast and DateTimeInterfaceTransformer:

Custom Formats

Override the format per property:

Using Carbon

The package automatically casts to the property type:
Or explicitly specify the type:

Multiple Date Formats

Accept different date formats from various sources:
When casting, the package searches for a valid format. When transforming without an explicit format, the first format in the array is used.
This is useful when receiving dates from iOS and React applications that use different underlying formats.

Casting with Different Timezones

Specify the timezone of incoming dates:
The date is created with the UTC timezone but represents the same moment in time as your application’s timezone.

Changing Timezones

On Cast

Convert the date to a different timezone during casting:
The time will be transformed. If the original time was in UTC, one or two hours (depending on daylight saving) will be added.

On Transform

Convert the timezone when transforming:

Complete Example