Difference between complete dates

Dúvidas, dicas e truques de PL/SQL. Aqui também vão assuntos relacionados a pacotes, triggers, funções, Java-Stored Procedures, etc
Post Reply
thiagoadvance
Rank: Estagiário Júnior
Rank: Estagiário Júnior
Posts: 2
Joined: Wed, 22 Feb 2012 8:44 am
Thiago Ramos Camargo
OCA
Desenvolvedor PL-SQL / Forms / Reports
Barretos - SP

Good morning,

I have the following problem between viewing the days, hours, minutes and seconds between two dates.

I will put the code below and I will explain later:

Select all

select sep.solicitacao_exame_id 
      ,pck_util.fnc_pega_class_descricao(se.centro_custo_id_origem) ccusto 
      ,sep.pro_id                         pro_id 
       
      ,((((((cl.dt_coleta - sep.dt_incl) * 24 * 60 * 60) / 3600)))-       
        (FLOOR((((cl.dt_coleta - sep.dt_incl) * 24 * 60 * 60) / 3600) /24) *24)) "HORAS_COLETA" 
         
      ,FLOOR((((cl.dt_coleta - sep.dt_incl) * 24 * 60 * 60) / 3600)/24) ||' DIAS '|| 
       ((ROUND((((cl.dt_coleta - sep.dt_incl) * 24 * 60 * 60) / 3600)))-       
        (FLOOR((((cl.dt_coleta - sep.dt_incl) * 24 * 60 * 60) / 3600) /24) *24)) || ':' || 
       ROUND((((cl.dt_coleta - sep.dt_incl) * 24 * 60 * 60) - 
        FLOOR(((cl.dt_coleta - sep.dt_incl) * 24 * 60 * 60) / 3600) * 3600) / 60) || ':' || 
       ROUND((((cl.dt_coleta - sep.dt_incl) * 24 * 60 * 60) - 
             FLOOR(((cl.dt_coleta - sep.dt_incl) * 24 * 60 * 60) / 3600) * 3600 - 
             (FLOOR((((cl.dt_coleta - sep.dt_incl) * 24 * 60 * 60) - 
                     FLOOR(((cl.dt_coleta - sep.dt_incl) * 24 * 60 * 60) / 3600) * 3600) / 60) * 60))) "TEMPO_COLETA" 
         
      ,((((((re.hr_recepcao - cl.dt_coleta) * 24 * 60 * 60) / 3600)))-       
        (FLOOR((((re.hr_recepcao - cl.dt_coleta) * 24 * 60 * 60) / 3600) /24) *24)) "HORAS_RECEPCAO"  
         
      ,FLOOR((((re.hr_recepcao - cl.dt_coleta) * 24 * 60 * 60) / 3600)/24) ||' DIAS '|| 
       ((ROUND((((re.hr_recepcao - cl.dt_coleta) * 24 * 60 * 60) / 3600)))-                 
        (FLOOR((((re.hr_recepcao - cl.dt_coleta) * 24 * 60 * 60) / 3600) /24) *24)) || ':' || 
       ROUND((((re.hr_recepcao - cl.dt_coleta) * 24 * 60 * 60) - 
        FLOOR(((re.hr_recepcao - cl.dt_coleta) * 24 * 60 * 60) / 3600) * 3600) / 60) || ':' || 
       ROUND((((re.hr_recepcao - cl.dt_coleta) * 24 * 60 * 60) - 
             FLOOR(((re.hr_recepcao - cl.dt_coleta) * 24 * 60 * 60) / 3600) * 3600 - 
             (FLOOR((((re.hr_recepcao - cl.dt_coleta) * 24 * 60 * 60) - 
                     FLOOR(((re.hr_recepcao - cl.dt_coleta) * 24 * 60 * 60) / 3600) * 3600) / 60) * 60))) "TEMPO_RECEPCAO"             
                    
      ,sep.dt_incl   
      ,cl.dt_coleta 
      ,re.hr_recepcao 
  from solicitacao_exame_procedimento SEP 
      ,solicitacao_exame              SE 
      ,procedimento                   pro 
      ,parametros_procedimento        pp 
      ,classificacao                  c 
      ,coleta_laboratorio             cl 
      ,realizacao_exame               re 
      ,laudo_html                     lh 
 where sep.dt_efetivacao           between '01012010' and '01012010' 
   and sep.efetivado               = 'S' 
   and sep.status_id               = 6 
   and sep.solicitacao_exame_id    = 1570476 
   and se.solicitacao_exame_id     = sep.solicitacao_exame_id 
   and pro.pro_id                  = sep.pro_id 
   and pp.pro_id                   = pro.pro_id  
   AND C.CLASSIFICACAO_ID          = PP.CLASSIFICACAO_ID  
   and cl.solic_exame_proc_id      = sep.solic_exame_proc_id 
   and cl.dt_coleta                = (Select max(cla.dt_coleta)  
                                        from coleta_laboratorio cla  
                                       where cla.solic_exame_proc_id = sep.solic_exame_proc_id) 
   and re.solic_exame_proc_id      = sep.solic_exame_proc_id  
   and re.filial_id                = 1 
   and lh.solic_exame_proc_id      = sep.solic_exame_proc_id 
 order by 1,3
The result is as follows:

Select all

 
SOLICITACAO_EXAME_ID	CCUSTO	PRO_ID	HORAS_COLETA	TEMPO_COLETA	HORAS_RECEPCAO	1570476             PEDIATRIA	1019    21,67777778    6 DIAS 22:41:40	0,73  TEMPO_RECEPCAO	     DT_INCL	           DT_COLETA	        HR_RECEPCAO 
0 DIAS 1:44:48	22/12/2009 09:26:41	29/12/2009 07:07:21	29/12/2009 07:51:09 

Using this SELECT works normal the time_coleta, but the time_recupation automatically adds 1 hour more, this occurs due to the use of round () in the second line of the select of the function To get this time.

But when I change the round () by Trunc () or Floor () the result is as follows:

Select all

 
SOLICITACAO_EXAME_ID	CCUSTO	PRO_ID	HORAS_COLETA	TEMPO_COLETA	HORAS_RECEPCAO	1570476             PEDIATRIA	1019    21,67777778    6 DIAS 21:41:40	0,73  TEMPO_RECEPCAO	     DT_INCL	           DT_COLETA	        HR_RECEPCAO 
0 DIAS 0:44:48	22/12/2009 09:26:41	29/12/2009 07:07:21	29/12/2009 07:51:09 
] The time_recupation is more corridigo in the field time_coleta is lost 1 hour.

I will use this code to bring 1 period of requisitions, but in case I had a problem with it, if someone has a solution thank you, I'm desperate because I discovered that they are using functions in my work and All in this error.

Thanks
DanielNN
Moderador
Moderador
Posts: 641
Joined: Mon, 03 Sep 2007 3:26 pm
Location: Fortaleza - CE
att,

Daniel N.N.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest