Created
March 11, 2013 19:10
-
-
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 }}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in your view you can do this : {{ $user->created_at->format('Y-m-d') }} , isn't that much easier?