Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between timestamp() and dateTime() methods of the Blueprint class

Tags:

In Laravel, the Illuminate\Database\Schema\Blueprint class has two methods that I would like to know concretely the difference between them.

$table->dateTime()  

and

$table->timestamp() 

Both store a date in the same way visibly. Someone to enlighten me?

like image 1000
Goms Avatar asked Dec 19 '17 00:12

Goms


1 Answers

So the secret to this is understanding what exactly each does.

The dateTime() and timestamp() functions here in Laravel use different table columns.

dateTime() uses DATETIME as the DB column type. timestamp() uses TIMESTAMP as the DB column type.

DATETIME and TIMESTAMP have a lot of similarities but the difference itself lies outside Laravel and more in MySQL.

Their major difference is the range. For DateTime its up to year 9999 while for timestamp its only up to year 2038. Other differences include the amount of bytes needed to store each.

I found a nice article that clearly states the similarities and differences of both here http://www.c-sharpcorner.com/article/difference-between-mysql-datetime-and-timestamp-datatypes/

Hope this helps.

like image 53
AceKYD Avatar answered Sep 19 '22 17:09

AceKYD