Irreversible, Compression and expansion work for a piston with ideal gas How can we calculate the work done by the piston or on the piston by including the internal pressure of the piston and not the external one. Because if the external pressure is doing work, the internal pressure might be too in the opposite direction, just like friction does. And I am specifically talking about "Irreversible change"
 A: 
How can we calculate the work done by the piston or on the piston by
  including the internal pressure of the piston and not the external
  one.

In an irreversible process the gas within the cylinder is not in equilibrium. There are pressure gradients in the gas . Because of this the internal pressure is not defined and only equals the external pressure at the piston interface.

Because if the external pressure is doing work, the internal pressure
  might be too in the opposite direction, just like friction does.

Your analogy is correct here. The process is irreversible due in part to viscous friction within the gas. For that reason the less net work is done in an irreversible than the same reversible process. You can determine this by comparing the work done if the process was carried out reversibly (where the gas pressure is assumed to be in equilibrium with the external pressure) to the work done irreversibly whee you only know the external pressure. 
For an example comparing the work done in a reversible vs. irreversible expansion of an ideal gas, see the following link.
https://chem.libretexts.org/Bookshelves/Physical_and_Theoretical_Chemistry_Textbook_Maps/Book%3A_Physical_Chemistry_(Fleming)/03%3A_First_Law_of_Thermodynamics/3.03%3A_Reversible_and_Irreversible_Pathways

But the analogy of calculating work done during expansion of an ideal gas irreversibly by taking the constant external pressure which acts in the opposite direction doesn't sound intuitive. Is there a way I can get the idea of what's actually happening.

Think about the rough mechanical friction analogy of pushing an object at constant velocity on a surface with friction. The kinetic friction force is equal and opposite to the force pushing on the object. The kinetic friction force is somewhat analogous to the internal pressure that opposes the external constant pressure, though in this case a single internal pressure of the entire gas is not defined. It only equals the external pressure at the piston interface. What's more not all of the work done by the gas is dissipated as heat, i.e., the process is not 100% irreversible as our mechanical analog. Some net work is done.

Also why isn't there any mention about the time for which the pressure
  is applied. Isn't that necessary??

For a reversible process the process is carried out quasi-statically, meaning infinitely slowly, so time to carry it out is infinite.
For an irreversible process the time is finite, but it doesn't matter because all we care about are the initial and final states of the system.  Taking the mechanical friction analogy, do we care how long it takes to move the object a certain distance? No. As long as it is constant velocity.
Hope this helps
A: It is important to be aware that, in an irreversible expansion or compression of an ideal gas, the gas does not satisfy the ideal gas law.  The ideal gas law applies only to a gas in thermodynamic equilibrium, or, in the case of a reversible process, a gas passing through a continuous sequence of thermodynamic equilibrium states.  In an irreversible process, the force $F_g$ exerted by the gas on the piston also includes a contribution from viscous damping stresses that always act in the direction opposite to the piston movement (and depend on the rate at which the piston is moving).  
If we do a force balance on the piston (assumed frictionless) during an irreversible expansion or compression, we obtain (using Newton's 2nd law):
$$F_g-P_{ext}A=m\frac{dv}{dt}$$where A is the area of the piston, m is its mass and $P_{ext}$ is the external force per unit area.  Note from this equation that, if the piston is massless, then the force exerted by the gas on the piston must exactly match the external force applied to the piston throughout the process (even when there are viscous damping stresses that contribute to the gas force).  If we multiply the above force balance equation by the piston velocity, we obtain:  $$F_gv=F_g\frac{dx}{dt}=P_{ext}\frac{dV}{dt}+mv\frac{dv}{dt}$$where dV/dt is the rate of change of gas volume:  $\frac{dV}{dt}=Av$.  If we integrate this equation with respect to time, we obtain the work done by the gas on its surroundings (the piston):  $$W_{g}=\int{F_gdx}=\int{P_{ext}dV}+\frac{1}{2}mv^2$$
Eventually, the piston will come to rest (as a result of viscous damping stresses within the gas) and the system will attain thermodynamic equilibrium.  At this point, irrespective of the mass of the piston, we will have simply $$W_g=\int{P_{ext}dV}$$Irrespective of whether the process is reversible or irreversible, this same equation will always apply.  It is just that, in a reversible process, the external pressure must also always match the pressure P=nRT/V calculated from the ideal gas law.
