change date format in query laravel

    By: Manu
    2 years ago

    Sp today we are going to see how we can change date format in query laravel, it can be achieved easily. To change date format in query laravel you can use below given code.

    So let's see how to change date format in query laravel

    DB::raw('DATE_FORMAT(tableName.created_at, "%d-%m-%y") as joingingDate'),
    


    In above code we are changing the date for mat complete query looks something like this, And this is how you change date format in query laravel.

    return User::where('user.id','=',$request['id'])
        ->select(
            DB::raw('DATE_FORMAT(users.created_at, "%d-%m-%y") as joingingDate'),
        )
        ->get();
    

    Now date format will change in case you want to change day,month or year in "%d-%m-%y" then you can check php date formatting documentation here.