megacolorboy

Back

Published on March 12th, 2021

Laravel

Convert to date from timestamp using Carbon

Using Carbon's method is basically a wrapper for , the main difference between the two methods is that you can add a timezone to Carbon's method.Here's a sample on how you can convert to date using timestamp using Carbon:Hope you found this useful!

1 minute read

Using Carbon's createFromFormat() method is basically a wrapper for DateTime::createFromFormat(), the main difference between the two methods is that you can add a timezone to Carbon's method.

Here's a sample on how you can convert to date using timestamp using Carbon:


<php
    function formatDate(Request $request) {
        return \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $request->date)->format('Y-m-d');
    }
?>

Hope you found this useful!