How to get created_at date only not time in laravel 5.4

How to get created_at date only not time in laravel 5.4

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Stripping Time from Laravel Carbon Instances

In Laravel 5.4, the created_at timestamp returned by your model is a Carbon instance. This object encapsulates both date and time information, which can be problematic when you need to display only the calendar date for user interfaces like registration confirmation pages or email summaries. The default behavior of echoing a Carbon object via Blade templates often results in the ISO 8601 format (2017-05-09 11:44:09), displaying both components regardless of your preference.

To isolate the date portion, you need to explicitly manipulate the Carbon instance using its built-in methods. The most direct approach is utilizing the format() method with a specific mask string. By passing 'Y-m-d' to this method, you instruct the underlying PHP DateTime parser to output only the year, month, and day.

{{ Auth::user()->created_at->format('Y-m-d') }}

This yields the clean output 2017-05-09. The format() method is part of the Carbon library's core functionality, meaning it is available without any additional Composer dependencies or configuration changes in a standard Laravel 5.4 setup. This approach is robust because it relies on string interpolation rules that are consistent across different locales when using the default Y-m-d mask.

If your application requires localization, simply changing the format string to 'd/m/Y' will output the date according to your configured locale settings (e.g., 09/05/2017). This flexibility is one of Carbon's primary advantages over native PHP DateTime formatting. However, be mindful that if you are building a global-facing application where specific regional formats might confuse users, sticking to the unambiguous Y-m-d or Y-m-d H:i:s patterns is often the safer engineering decision unless you have explicitly set locale preferences per user session.

An alternative strategy involves casting the Carbon instance back to a native PHP string before formatting, though this adds unnecessary complexity in most cases. You might see code like Auth::user()->created_at->toDateTimeString('Y-m-d'). While technically valid, using format() directly is more idiomatic within the Laravel ecosystem and performs slightly better as it avoids the intermediate string conversion step.

It is also worth noting how this interacts with your database configuration. If you have changed the default date column type from datetime to date, the model will not automatically create a created_at timestamp field unless explicitly configured in the $fillable array or via migration defaults. In such scenarios, you might encounter null values if the field does not exist. The code snippet provided in the source material attempts to handle this by falling back to the user's email address:

isset(Auth::user()->created_at) ? Auth::user()->created_at : Auth::user()->email

While this fallback ensures the Blade template doesn't break if the timestamp is missing, it mixes data types (a Carbon instance or a string) in a ternary operator. This can lead to unexpected rendering issues if the email address itself contains characters that interfere with date formatting logic later in the pipeline. A cleaner pattern for handling optional timestamps is to check for nullity before applying the format method:

{{ Auth::user()->created_at ? Auth::user()->created_at->format('Y-m-d') : '-' }}

This ensures that if the created_at attribute is absent, a placeholder or default string is rendered instead of attempting to format an empty object. Always ensure your Carbon instances are aware of the timezone you intend to display; otherwise, the date might shift unexpectedly depending on the server's timezone configuration. The format() method respects this, so ensuring config('app.timezone') is set correctly in your app.php file is a prerequisite for consistent date presentation across all users.

Our network