Reputation: 973
I have one column as closed_date and data type is timestamp. I want to add the date in unix timestamp e.g. 1556801668. I don't know how to do that in Laravel.
Upvotes: 9
Views: 9558
Reputation:
I you want to do this within the model, you can use castings:
protected $casts = [
'closed_date' => 'timestamp',
];
Upvotes: 3
Reputation: 3022
If you have a Date string, for instance, you can create a Carbon
object and store it directly into database.
Laravel will convert that object to the correct type for the database.
Upvotes: 0
Reputation: 4499
use php strtotime()
function to convert time.
Example
$time = '2019-01-01'
$timeStamp = strtotime($time);
// will output 1546300800
Upvotes: 7