mardi 3 janvier 2017

Finding days between two dates in laravel

I have to dates. Now, I need to find the difference between these two for further calculations.

I tried different ways but I am not able to fix the issues. Can anyone tell me the best way to do it.

My code is:

public function leaveRequest(request $request)
{
    $fdate=$request->Fdate;
    $tdate=$request->Tdate;

    $start = Carbon::parse($fdate)->format('Y/m/d');
    $end =  Carbon::parse($tdate)->format('Y/m/d');

    $days = $end->diffInDays($start);
    /*$days=date_diff($end,$start);*/
    echo $days;
    exit;

    $user = User::findOrFail(Auth::user()->id);
    Mail::send('pages.leave', ['user' => $request,'userId'=>$user], function ($m) use ($request) {
        $m->to($request->Email)->subject('Leave Request!');
    });

    DB::table('leaves')->insert(
        ['user' => Auth::user()->id, 'request_date' => Carbon::now(),'start' => $start,'end' => $end,'permissions' => "Pending",'leave_status' => "Active"]
    );

    return redirect()->back()->with('message','Your request has sent');
}

If I can get the days then I can insert it into the leaves table.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire