Carbon timeformat I am using angular js to grab the time the user inputs into a form. And it returns weird like 2017-04-18T16:07:57Z. Now I am trying to use Carbon to put it in the right format of 16:07:57.
Here is my method of saving/posting the form
public function store(Request $request) {
$event = new Event();
$event->event_title = $request->input('event_title');
$event->event_description = $request->input('event_description');
$event->event_location = $request->input('event_location');
$event->event_date = $request->input('event_date');
$event->event_time = Carbon::now();
$event->save();
//return response()->json(['event'=>$event, 'user'=>$user], 201);
return 'Event record successfully created';
}
from the docs:
$dt = Carbon::create(1975, 12, 25, 14, 15, 16);
var_dump($dt->toDateTimeString() == $dt); // bool(true) => uses __toString()
echo $dt->toDateString(); // 1975-12-25
echo $dt->toFormattedDateString(); // Dec 25, 1975
echo $dt->toTimeString(); // 14:15:16
echo $dt->toDateTimeString(); // 1975-12-25 14:15:16
echo $dt->toDayDateTimeString(); // Thu, Dec 25, 1975 2:15 PM
// ... of course format() is still available
echo $dt->format('l jS \\of F Y h:i:s A'); // Thursday 25th of December 1975 02:15:16 PM
add ->format('m-d-Y') or however you'd like the date to be formated
Carbon::now()->format ...
or Carbon::now()->toDate()...
Try this
Carbon::now()->format('h:i:s');
that works!! Instead of getting the current time how would I grab the time they are entering in the form? to time string??
@mturner20
what is your input for the time like?
$model->time_element = Carbon::createFromFormat('m/d/Y h:i a', $request->time_element);
this will let you create a carbon date from a passed in date/time input
Please sign in or create an account to participate in this conversation.