Reputation: 4141
I want to display something like 01 June from created_at column. I tried doing something like this which I know, is quite dumb thing.
<span class="day">{{date('m', $new->created_at)}}</span>
Upvotes: 14
Views: 81604
Reputation: 89
$id = 1 ;
$users=data::find($id);//Fetching record using primary key from data named table
$month=$users->created_at->format('m'); //getting month
$day=$users->created_at->format('d');//getting day
dd("Month : ".$month."\nDay : ".$day);//Printing Month & day
Upvotes: 0
Reputation: 618
You can use Carbon for that. For example, you want to get day from date, then you can follow below code ;
Carbon::parse($data->created_at)->format('l');
This will respond to you as day name.
Upvotes: 0
Reputation: 1148
$timestamp = strtotime($new->created_at);
//Uppercase letters gives day, month in language(Jan, Third, etc)
$day = date('D', $timestamp);
$month = date('M', $timestamp);
//lowercase letters gives day, month in numbers(1, 3, etc)
$day = date('d', $timestamp);
$month = date('m', $timestamp);
//use a combination of both, eg: 01 June
$final_Date = date('d', $timestamp) .' '. date('M', $timestamp);
Upvotes: 5
Reputation: 9369
Using Carbon it's too easy. see docs here
You can do it like this,
<span class="day">{{\Carbon\Carbon::parse($new->created_at)->format('d M')}}</span>
Upvotes: 5
Reputation: 27503
{{ $object->created_at->format('d M') }}
for day and month
{{ $object->created_at->format('M') }}
for only month
{{ $object->created_at->format('d') }}
for only day
$object
referred to your passed variable from the controller to the blade
Upvotes: 34
Reputation: 5759
$timestamp = strtotime($new->created_at);
$day = date('D', $timestamp);
$month = date('M', $timestamp);
Upvotes: 3
Reputation: 124
use
echo date('d M',$new->created_at));
For manipulation of date & time you can go through http://php.net/manual/en/function.date.php
Upvotes: 0