Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel need to display only date not time using the carbon class

currently i am using

Carbon::now()

it displays

2015-03-10 23:23:46

but i only need

2015-03-10

like image 228
Muhammad Avatar asked Mar 10 '15 11:03

Muhammad


People also ask

How does Carbon Laravel get time?

Say I want to retrieve the date and time and output it as a string. $mytime = Carbon\Carbon::now(); echo $mytime->toDateTimeString(); This will output in the usual format of Y-m-d H:i:s , there are many pre-created formats and you will unlikely need to mess with PHP date time strings again with Carbon.

How to make date/time easier in Laravel and PHP with carbon?

Easier Date/Time in Laravel and PHP with Carbon 1 Setup. In order to use Carbon, you’ll need to import Carbon from the Carbon namespace. ... 2 Getting a Specific Date/Time 3 Creating Dates with More Fine Grained Control. ... 4 Manipulating the Date/Time. ... 5 Getters and Setters. ... 6 Formatting. ... 7 Relative Time. ... 8 Conclusion. ...

How do I use carbon in Laravel?

In order to use Carbon, you’ll need to import Carbon from the Carbon namespace. Luckily for us, Carbon is already included in Laravel. Whenever we need to use Carbon, we can import it like so: After importing, let’s explore what Carbon provides. Get the current time: Current time can also be retrieved with this instantiation: Get today’s date:

Does Laravel support dates and times?

Ralph J. Smit Laravel & PHP-developer. At some point, almost every Laravel application needs to work with dates and times. But managing dates and times is sometimes ridiculously complex, because of timezones. In which timezone do you store dates and times? How do you calculate differences between times?

How to manage timezones in Laravel?

Here is the most basic rule of managing timezones in Laravel: In the config/app.php you can set the default timezone for your application. By default this is set to UTC, but in theory you could change it. Please note that storing times in a timezone other than UTC+0 is highly discouraged.


1 Answers

http://carbon.nesbot.com/docs/#api-formatting

$dt = Carbon::now(); echo $dt->toDateString(); // Equivalent: echo $dt->format('Y-m-d'); 
like image 102
Tjkoopa Avatar answered Sep 19 '22 13:09

Tjkoopa