Couldn't you just store it as a datetime field?
Formatting User Selected Date & Time With Carbon
Hey,
I'm building form that lets the user set a due date with a time, I'm using Bootstrap 3 Datepicker v4for the front end date picker, when the date / time is selected it is formatted like so "m/d/Y H:g A" so it looks like this in the field "10/16/2015 9:00 AM" I need to convert this to a timestamp before saving it to the database. How do you go about this, should I do this in my store function within the controller or in the model?
Here is the code I'm trying to use within my controller but I don't think I'm using Carbon correctly as its saving the date correctly but the time is not, i.e. its saved like "2015-10-16 00:00:00", without the time.
$request['due_at'] = Carbon::createFromFormat('m/d/Y H:g A', $request->due_at)->toDateTimeString();
What would you suggest?
@Presto You should change the g to an i. You also probably don't need toDateTimeString().
$request['due_at'] = Carbon::createFromFormat('m/d/Y H:i A', $request->due_at);
Please or to participate in this conversation.