Jump to content
Fórum Script Brasil
  • 0

Somar Data


neo
 Share

Question

3 answers to this question

Recommended Posts

  • 0

<?

function datediff($dt1, $dt2) {

    if (!ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", $dt1) Or !ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", $dt1)) {

        return "Uma das datas é Inválida!";

    } else {

        $date1 = explode("/", (string) $dt1);

        $date2 = explode("/", (string) $dt2);

        $pri = $date1[1] . "/" . $date1[0] . "/" . $date1[2];

        $seg = $date2[1] . "/" . $date2[0] . "/" . $date2[2];

        $data1 = strtotime($pri);

        $data2 = strtotime($seg);

        $maior = max($data1, $data2);

        $menor = min($data1, $data2);

        $res = $maior - $menor;

        $dias = ((($res / 60) / 60) / 24) + 1;

        return $dias;

    }

}

$data1 = "01/09/2004";

$data2 = "01/10/2004";

$dif = datediff($data1, $data2);

echo "Diferença é igual a " . $dif . " dia(s) !";

?>

Foi postado pelo Ppgsalomao(Pedro) no tópico de scripts.

Abraços.

Link to comment
Share on other sites

  • 0

Putz, entendi mal, voce quer somar as datas esta função é para somar datas.. desculpa. Mas aqui esta:

<?

$dias = 7; // Dias a + ou a - a ser contado

$opera = "+"; // Coloque a operação se + ou -

if($opera=="+") $data = date("d/m/Y H:i:s", time() + 86400 * $dias);

if($opera=="-") $data = date("d/m/Y H:i:s", time() - 86400 * $dias);

echo $data;

?>

Foi postado pelo gladisson.

abraços.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      150.7k
    • Total Posts
      648.5k
×
×
  • Create New...