Skip to content

Instantly share code, notes, and snippets.

@msurguy
Created March 11, 2013 19:10
Show Gist options
  • Save msurguy/5136810 to your computer and use it in GitHub Desktop.
Save msurguy/5136810 to your computer and use it in GitHub Desktop.
Get created_at date in different formats with Laravel in PHP 5.2+. Put this code in your model (for example models/users.php) and in your views do {{ $user->short_created_at }}
public function get_short_created_at()
{
$date = $this->get_attribute('created_at');
if (is_string($date)){
$dateObject = DateTime::createFromFormat('Y-m-d H:i:s', $date);
return $dateObject->format('Y-m-d');
}
return $date;
}
@SeifBh
Copy link

SeifBh commented Jun 15, 2016

@xfchris lol Thankyou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment