1) Convert the dates to PHP timestamp. Ex:
$entrada = mktime(0,0,0,4,29,2014); //29/04/2014
$saida = mktime(0,0,0,5,3,2014); // 03/05/2014
2) Assess whether there is a difference in the months. If there is a difference you should do two calculations, one for each month. If there is not you just subtract the dates.
$mesEntrada = date('n', $entrada);
$mesSaida = date('n', $saida );
if ($mesEntrada != $mesSaida)
{
$diasTrabalhadosMesEntrada = (date("t", $entrada)-date("j",$entrada))+1; // Subtrai o total de dias do mes pelo dia de entrada.
$diasTrabalhadosMesSaida = date('j', $saida ); // A quantidade de dias trabalhados é igual ao dia de saída.
// Inserir no BD...
}
else
{
// Apenas 1 mes (mesEntrada igual a mesSaida);
$diasTrabalhados = date("j",$saida)-date("j",$entrada);
// Inserir no BD...
}
With regard to DB, you can create a table that stores the month, year, and amount of days worked (columns, month, year, and working days) in separate columns. I also recommend creating a history table that stores all employee entries and exits (official columns, input and output).
I would suggest looking at link for a better understanding.
I did not test the code, it's just a targeting.