How to print date without time in laravel?

by elisha_langworth , in category: PHP Frameworks , 2 months ago

How to print date without time in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by mallory_cormier , 2 months ago

@elisha_langworth 

You can use the Carbon library in Laravel to print the date without the time. Here's an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
use CarbonCarbon;

// Get the current date and time
$date = Carbon::now();

// Format the date without the time
$formattedDate = $date->format('Y-m-d');

// Print the date without the time
echo $formattedDate;


This will output the current date in the format 'Y-m-d' (year-month-day) without the time component. You can change the format string to suit your needs.