Search code examples
phplaravelphp-carbon

Cannot format Carbon date


I am having trouble formatting a Carbon date.

Here is my code:

use Carbon\Carbon;

$datePosted = Carbon::now();
$datePosted->toRssString();


DB::table('entries')->insert(
    array('body' => $request->body,
          'date_posted' => $datePosted)
);

According to this website, toRssString() should format the date as Thu, 26 Oct 2017 20:09:59 -0500. However it is being put into the database in this format 2017-10-26 20:09:59

Can anybody tell me what is wrong?


Solution

  • You need to assign result to some variable and then pass it:

    $result = $datePosted->toRssString();
    

    Or you can do it directly in array:

    array('body' => $request->body,
          'date_posted' => $datePosted->toRssString())