1) Convert 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) Evaluate if there is a difference in the months. If there is a difference you should make two calculations, one for each month. If there is not you just need to 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...
}
Regarding the BD, you can create a table that stores in different columns the month, year and number of days worked (columns employee, month, year and days worked). I also recommend creating a history table that stores all employee inputs and outputs (function columns, input and output).
I suggest consulting http://www.php.net/manual/en/function.date.php for a better understanding.
I didn’t test the code, it’s just a direction.
Hello, try to do something like this:
$dia2 = date('d')+2;
if($dia2 !== date('d')){
 //Hoje nao é o dia de saída insere a data actual
 //insert into x where xxx values date('d/M/Y');
 } else {
 //insert into x where xxx values date
 }
– Edilson