2

Is it possible to select a timestamp column as a Carbon date object using the query builder? DateCreated in the snippet below:

$entities = DB::table('translation_review as tr')
    ...
    ->select('tr.AuthorID', 't.LanguageID', 't.DateCreated' /* <--- this one! */)
    ->get();

Update 1:
I have solved this manually by iterating over the result set and changing the DateChanged property manually, but I am not satisfied with this solution. It feels inelegant.

foreach ($entities as $entity)
    $entity->DateCreated = Carbon::createFromFormat('Y-m-d H:i:s', $entity->DateCreated);
Leonard
  • 3,012
  • 2
  • 31
  • 52

1 Answers1

1

If you don't use Eloquent, then you should create a Carbon object manually:

$carbonDate = Carbon::parse($data['DateCreated'])
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279