Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

david001's avatar

How to change day of date

controller:

public function store(ContractRequest $request,$operatorId)
{
 //dd($request->all());

    $contractData = $request->all();
    $contractData['operator_id'] = $operatorId;

    if ($this->contract->create($contractData)) {
        return redirect()->route('admin.operator.{id}.contracts.index',[$operatorId])->with('success', 'Contract
        successfully
        created.');

    }

        return redirect()->route('admin.contracts.index')->with('error', 'Contract could not be created.');
    }

view:

<div class="form-group">
    {!! Form::label('title', 'Start Date:', ['class'=>'col-sm-2 control-label'])!!}
    <div class="col-sm-7">
        {!! Form::date('start_date',null, ["class"=>"form-control",'required'])!!}
    </div>
</div>

<div class="form-group">
    {!! Form::label('title', 'End Date:', ['class'=>'col-sm-2 control-label'])!!}
    <div class="col-sm-7">
        {!! Form::date('end_date',null, ["class"=>"form-control"])!!}
    </div>
</div>

<div class="form-group">
    {!! Form::label('title', 'Remarks:', ['class'=>'col-sm-2 control-label'])!!}
    <div class="col-sm-7">
        {!! Form::textarea('remark',null, ["class"=>"form-control",'cols'=>'10','rows'=>'5'])!!}
    </div>
</div

my question :This is contract form and generally contract that should start form 01 day and end at30,29 or 31 day of month. if user select 2016-2-4as start date and 2017-05-31end date from date picker then start date should be saved as2016-2-1.How can make this ,start dateday should always be one ie01

start data 2016-o2-o4 should be saved as2016-02-01 ie 01 at end for day

0 likes
6 replies
jlrdw's avatar

Have you looked at format functions.

jlrdw's avatar

Use a string function to correct it, or use a custom method to pick dates.

willvincent's avatar
Carbon::parse($start_date)->startOfMonth()->format('Y-m-d');
david001's avatar

what about end day,it should be 29,30 or 31 according to month days

willvincent's avatar
$start_date = Carbon::parse($start_date)->startOfMonth()->format('Y-m-d');
$end_date = Carbon::parse($end_date)->endOfMonth()->format('Y-m-d');

Carbon is already included with laravel.. and using it makes date manipulation incredibly simple.. you should familiarize yourself with it's documentation: http://carbon.nesbot.com/docs/

Please or to participate in this conversation.