Login   Register  
PHP Classes
elePHPant
Icontem

File: data

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Fagner Fernandes  >  Datas class  >  data  >  Download  
File: data
Role: Example script
Content type: text/plain
Description: data.php
Class: Datas class
Compute the difference of time between dates
Author: By
Last change:
Date: 2010-08-13 20:08
Size: 2,802 bytes
 

Contents

Class file image Download
<?PHP 
include("datas.class.php"); 

?> 
<html> 
<head> 
</head> 
<title>Diferenca de datas</title> 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
</head> 
<body> 
<form action="data.php" method="post">
    <table>
        <tr>
            <td>
                Data inicial: 
            </td>
            <td>
                <input type="text" name="data_inicial" id="data_inicial" value="01/02/2010 08:00"> 
            </td>
        </tr>
        <tr>
            <td>
                Data final: 
            </td>
            <td>
                <input type="text" name="data_final" id="data_final" value="04/02/2010 11:30">
            </td>
        </tr>
        <tr>
            <td>
            
            </td>
            <td>
                <select name="tipo" id="tipo">
                    <option value="D">Dias exatos</option>
                    <option value="d">Dias arredondados</option>
                    <option value="H">Horas exatas</option>
                    <option value="h">Horas arredondadas</option>
                    <option value="m">Minutos</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                <input type="submit" Value="Enviar">
            </td>
        </tr>
    </table>
</form>

<?php

            
if( $_POST['data_inicial'] != "" ){
                
$data1     $_POST['data_inicial'];
                
$data2     $_POST['data_final'];
                
$tipo    $_POST['tipo'];
                
                echo 
"Data final:" $data1 ."<br />";
                echo 
"Data inicial:" $data2 ."<br /><br />";
                
                switch ( 
$tipo ) {
                    case 
"D":
                            echo 
datas::Diferenca($data1,$data2,"D");
                            echo 
" dias exatos.<br>";
                        break;
                    case 
"d":
                            echo 
datas::Diferenca($data1,$data2,"d");
                            echo 
" dias arredondados.<br>";
                        break;
                    case 
"H":
                            echo 
datas::Diferenca($data1,$data2,"H");
                            echo 
" horas exatas.<br>";
                        break;
                    case 
"h":
                            echo 
datas::Diferenca($data1,$data2,"h");
                            echo 
" horas arredondadas.<br>";
                        break;
                    case 
"m":
                            echo 
datas::Diferenca($data1,$data2,"m");
                            echo 
" minutos <br>";
                        break;
                }
            }

?>
<br /><br />
Leiame:<br />
Esta função retorna diferença entre as datas em Dias, Horas ou Minutos<br />
        Function Diferenca(data maior, [data menos],[dias horas ou minutos])<br />
        Primeiro parametro, Data de inicio, no formato 04/05/2006 12:00<br />
        Se não passado o seundo parametro, dá o valor da data atual<br />
        Terceiro parametro, diferença a ser retornada:<br />
<br />
        "m" Minutos<br />
        "H" Horas<br />
        "h": Horas arredondada<br />
        "D": Dias<br />
        "d": Dias arredontados<br />


</body> 
</html>