PHPackages                             maartenpaauw/laravel-date-time-zone-cast - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. maartenpaauw/laravel-date-time-zone-cast

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

maartenpaauw/laravel-date-time-zone-cast
========================================

A Laravel cast to convert strings to DateTimeZone instances

1.0.0(9mo ago)3138[4 PRs](https://github.com/maartenpaauw/laravel-date-time-zone-cast/pulls)MITPHPPHP ^8.2CI passing

Since Jul 27Pushed 4mo agoCompare

[ Source](https://github.com/maartenpaauw/laravel-date-time-zone-cast)[ Packagist](https://packagist.org/packages/maartenpaauw/laravel-date-time-zone-cast)[ Docs](https://github.com/maartenpaauw/laravel-date-time-zone-cast)[ GitHub Sponsors]()[ RSS](/packages/maartenpaauw-laravel-date-time-zone-cast/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (12)Versions (6)Used By (0)

A Laravel cast to convert strings to DateTimeZone instances
===========================================================

[](#a-laravel-cast-to-convert-strings-to-datetimezone-instances)

[![Latest Version on Packagist](https://camo.githubusercontent.com/20e8a4e6700df4f392f2eea465a2d91910a466452ec57c79a147c2ac309b371e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61617274656e70616175772f6c61726176656c2d646174652d74696d652d7a6f6e652d636173742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maartenpaauw/laravel-date-time-zone-cast)[![GitHub Tests Action Status](https://camo.githubusercontent.com/8921c015d4f95f4fd79bef15737a32d65d1b9662be18e586209a8c2ba53cf039/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61617274656e70616175772f6c61726176656c2d646174652d74696d652d7a6f6e652d636173742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/maartenpaauw/laravel-date-time-zone-cast/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/8c1f60bb7df7a2bc532c124f166b47b76a90a19768f4bee471d587a862592c68/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61617274656e70616175772f6c61726176656c2d646174652d74696d652d7a6f6e652d636173742f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/maartenpaauw/laravel-date-time-zone-cast/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/a75c0559e79f9ddef1eb4661eea2b04101f3261f443f4769cff62779013dcd5d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61617274656e70616175772f6c61726176656c2d646174652d74696d652d7a6f6e652d636173742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maartenpaauw/laravel-date-time-zone-cast)

A Laravel cast that allows you to store and retrieve `DateTimeZone` objects in your Eloquent models. This cast automatically converts timezone strings (e.g. 'Europe/Amsterdam') to PHP `DateTimeZone` instances and vice versa when interacting with your database.

Support Me
----------

[](#support-me)

 [ ![Model States for Filament](https://raw.githubusercontent.com/maartenpaauw/model-states-for-filament-docs/main/assets/images/model-states-for-filament-banner.jpg) ](https://filamentphp.com/plugins/maartenpaauw-model-states)

You can support me by [buying Model States for Filament](https://filamentphp.com/plugins/maartenpaauw-model-states).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require maartenpaauw/laravel-date-time-zone-cast
```

Usage
-----

[](#usage)

### 1. Add the Cast to Your Model

[](#1-add-the-cast-to-your-model)

Add the cast to your Eloquent model's `$casts` array:

```
