D
D
Dmitry Kuznetsov2016-04-07 17:53:12
Working with date/time
Dmitry Kuznetsov, 2016-04-07 17:53:12

How to work with date in Laravel?

Previously, in Laravel, all dates were stored as a simple number (received through the time() function). Now you need to use the standard means of getting the date in Lara.
In Lara, by default, when creating a record in the database, the "created_at" column is used, which uses the "timestamp" type.
How can I get the date in the format I need?
PS: used to be: "date('dmY H:i:s')".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D', 2016-04-07
@dima9595

In Laravel, the Model has a protected $dates variable.
All database fields written to this variable are automatically converted to a Carbon\Carbon instance, and then you can work with them simply:

<?php

class MyModel extends Model {
  protected $dates = ['signed_at'];
}

// ....

$model = MyModel::first();
echo $model->signed_at->format('d.m.Y H:i:s');

Read more here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question