Hora
Hora
Identificar que se a hora for ( 06:00:01 entre este período 12:00:00) e 1
Identificar que se a hora for ( 12:00:01 entre este período 18:00:00) e 2
Identificar que se a hora for ( 18:00:01 entre este período 24:00:00) e 3
Identificar que se a hora for ( 24:00:01 entre este período 06:00:00) e 4
Como que faço para calcular e identificar se esta entre estes período e daí dar um numero para identificação de períodos
Identificar que se a hora for ( 06:00:01 entre este período 12:00:00) e 1
Identificar que se a hora for ( 12:00:01 entre este período 18:00:00) e 2
Identificar que se a hora for ( 18:00:01 entre este período 24:00:00) e 3
Identificar que se a hora for ( 24:00:01 entre este período 06:00:00) e 4
Como que faço para calcular e identificar se esta entre estes período e daí dar um numero para identificação de períodos
Rr
Curtidas 0
Respostas
Bruno Belchior
06/10/2005
você quem isso em delphi ou SQL?
GOSTEI 0
Bruno Belchior
06/10/2005
Em delphi:
function TForm1.RetornaTipo(Data: TDateTime): Shortint; var H, M, S: Byte; begin H := HourOf(Data); M := MinuteOf(Data); S := SecondOf(Data); if ((H in [6..11]) or ((H = 12) and (M = 0) and (S = 0))) and ((H = 6) and (M = 0) and (S = 0) = False) then Result := 1 else if (H in [12..17]) or ((H = 18) and (M = 0) and (S = 0)) then Result := 2 else if (H in [18..23]) or ((H = 0) and (M = 0) and (S = 0)) then Result := 3 else if (H in [0..5]) or ((H = 6) and (M = 0) and (S = 0)) then Result := 4 else Result := -1 end;
GOSTEI 0
Bruno Belchior
06/10/2005
e em PSQL:[code]e em PSQL:[code]create procedure RetornaTipo(dtData TimeStamp)
returns (Resultado Smallint)
as
declare variable H Smallint;
declare variable M Smallint;
declare variable S Smallint;
begin
select Extract(Hour from :dtData) from RDB$Database into H;
select Extract(Minute from :dtData) from RDB$Database into M;
select Extract(Second from :dtData) from RDB$Database into S;
if (((H between 6 and 11) or ((H = 12) and (M = 0) and (S = 0))) and
(not ((H = 6) and (M = 0) and (S = 0)))) then
Resultado = 1;
else if ((H between 12 and 17) or ((H = 18) and (M = 0) and (S = 0))) then
Resultado = 2;
else if ((H between 18 and 23) or ((H = 0) and (M = 0) and (S = 0))) then
Resultado = 3;
else if ((H between 0 and 5) or ((H = 6) and (M = 0) and (S = 0))) then
Resultado = 4;
else
Resultado = -1;
suspend;
end;[/code]
returns (Resultado Smallint)
as
declare variable H Smallint;
declare variable M Smallint;
declare variable S Smallint;
begin
select Extract(Hour from :dtData) from RDB$Database into H;
select Extract(Minute from :dtData) from RDB$Database into M;
select Extract(Second from :dtData) from RDB$Database into S;
if (((H between 6 and 11) or ((H = 12) and (M = 0) and (S = 0))) and
(not ((H = 6) and (M = 0) and (S = 0)))) then
Resultado = 1;
else if ((H between 12 and 17) or ((H = 18) and (M = 0) and (S = 0))) then
Resultado = 2;
else if ((H between 18 and 23) or ((H = 0) and (M = 0) and (S = 0))) then
Resultado = 3;
else if ((H between 0 and 5) or ((H = 6) and (M = 0) and (S = 0))) then
Resultado = 4;
else
Resultado = -1;
suspend;
end;[/code]
GOSTEI 0
Bruno Belchior
06/10/2005
corrigindo...
create procedure RetornaTipo(dtData TimeStamp) returns (Resultado Smallint) as declare variable H Smallint; declare variable M Smallint; declare variable S Smallint; begin select Extract(Hour from :dtData) from RDB$Database into H; select Extract(Minute from :dtData) from RDB$Database into M; select Extract(Second from :dtData) from RDB$Database into S; if (((H between 6 and 11) or ((H = 12) and (M = 0) and (S = 0))) and (not ((H = 6) and (M = 0) and (S = 0)))) then Resultado = 1; else if ((H between 12 and 17) or ((H = 18) and (M = 0) and (S = 0))) then Resultado = 2; else if ((H between 18 and 23) or ((H = 0) and (M = 0) and (S = 0))) then Resultado = 3; else if ((H between 0 and 5) or ((H = 6) and (M = 0) and (S = 0))) then Resultado = 4; else Resultado = -1; suspend; end;
GOSTEI 0