Jump to content
Fórum Script Brasil
  • 0

Diferenças entre datas


Peter Link

Question

Boa Noite, Gostaria de saber como calculo diferenças entre datas no php ?

Fiz varias buscas no google mas não consegui fazer funcionar nada.

Assim o resultado que eu quero é exatamente o resultado dessa query

$conexao->set('sql',"SELECT 
                                    (
                                        (
                                        SELECT TO_DATE(ULTIMA_ALTERACAO,'DD/MM/RRRR') 
                                            FROM FACT_SD_STATUS 
                                            WHERE 
                                                ID_SOLICITACAO='$solicitacaoID' AND 
                                                STATUS = 'Finalizada'
                                        ) 
                                            - 
                                        (
                                            SELECT TO_DATE(ULTIMA_ALTERACAO,'DD/MM/RRRR') 
                                                FROM FACT_SD_STATUS 
                                                WHERE 
                                                    ID_SOLICITACAO='$solicitacaoID' AND 
                                                    STATUS = 'SD $solicitacaoID Aberta'
                                        )
                                    ) AS TMA
                                 FROM DUAL"
                        );
            $aplica = $conexao->query();
            $timestamp = oci_result($aplica, 'TMA');
Porem não posso usar essa query, pois necessito dela dentro de um WHILE e com isso deixa muito lenta a consulta, chegando a pagina expirar, dai precisava fazer isso direto no php, pegando as datas conforme exemplo e calculando a diferença entre elas
$conexao->set('sql',"SELECT 
                                    ULTIMA_ALTERACAO 
                                            FROM FACT_SD_STATUS 
                                            WHERE 
                                                ID_SOLICITACAO={$solicitacaoID} AND 
                                                STATUS = 'Finalizada'
                                ");
            $aplica2 = $conexao->query();
            $tma1 = oci_fetch_array($aplica2);

            $conexao->set('sql',"SELECT 
                                    ULTIMA_ALTERACAO 
                                            FROM FACT_SD_STATUS 
                                            WHERE 
                                                ID_SOLICITACAO={$solicitacaoID} AND 
                                                STATUS = 'Finalizada'
                                ");
            $aplica3 = $conexao->query();
            $tma2 = oci_fetch_array($aplica3);

Ou como segunda opção alguma forma de converter essas datas para segundo, dai faço a diferença entre as duas e converto para dias.

Desde já agradeço!

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

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.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652.1k
×
×
  • Create New...