Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a Laravel schema builder dateTimeTz example look?

As it's listed on the Available Column Types section here: https://laravel.com/docs/5.2/migrations#creating-columns

We can define a new column with the type 'dateTimeTz', however it gives little to no clue how it should look or if it's just like a standard DateTime object. I've been searching all over the places about this type, but couldn't see anything relevant.

Can somebody explain the difference between this one and 'dateTime'?

like image 893
Cristian F. Avatar asked Feb 06 '23 12:02

Cristian F.


2 Answers

The datetimeTz column field is actually imported from Doctrine's datetimetz with additional timezone information.

In general, this helps to work with PHP's Datetime object by setting the timezone information. To learn more about when and when not you should use it, you should read this https://derickrethans.nl/storing-date-time-in-database.html

like image 189
Chibueze Opata Avatar answered Feb 16 '23 03:02

Chibueze Opata


It looks like this is just an option for database systems that support two different types -- datetime without timezone information and datetime with timezone information.

I'd guess that if you use the dateTimeTz type with a database that doesn't support it, it would fall back to dateTime.

Similar question here.

like image 28
Samsquanch Avatar answered Feb 16 '23 03:02

Samsquanch