by changing this:
format: 'MM/DD/YYYY hh:mm A'
to this:
format: 'YYYY-MM-DD hh:mmA'
The Carbon way would be this:
$now = Carbon\Carbon::parse('2020-05-09 23:14:00');
$now->format('Y-m-d h:iA')
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
This date is stored in my database 2020-05-09 23:14:00 But I want to get the date in the format of 2020-05-09 11::14PM How can I get this?
#this is my blade this is the script
<div class="col">
<div class="form-group">
<label>Due date:</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<i class="far fa-calendar-alt"></i>
</span>
</div>
<input
type="text"
class="form-control float-right"
id="duetime"
name="due_time"
value="{{$task->due_time}}"
/>
</div>
</div>
</div>
#script
$("#duetime").daterangepicker({
// startDate: moment().startOf('hour'),
// startDate: moment().add(1, 'days'),
startDate: false,
// minDate: moment().add(1, 'days'),//This will not do accessing the previous date
minYear: 1901,
// maxYear: parseInt(moment().format('YYYY'),10),//For this year not show future years
showDropdowns: true,
singleDatePicker: true,
timePicker: true,
timePicker24Hour: false,
timePickerIncrement: 05,
drops:"up",
locale: {
format: 'MM/DD/YYYY hh:mm A'
}
});
and I'm using the daterangepicker script https://www.daterangepicker.com/#examples
Okay @neeraj1005
then try this:
public function getDueTimeAttribute($date)
{
return Carbon::parse($date)->format('Y-m-d h:iA');
}
Again you should know if the due_time can be null or not. If it can be, then you should add the check, otherwise it will throw an exception.
Please or to participate in this conversation.