good morning!
I have a little problem, could you help?
I need to add 2 seconds to my current time.
From my date/time I need to add 2 seconds and get only hour/minute/seconds.
I tried in a way like sum. I concatenate hour/minute/second and add 2 seconds.
But it's not being assertive... =/
Below is the method I tried:
DECLARE @ACTUAL_DATE VARCHAR (6);
SET @ACTUAL_DATE = (SELECT FORMAT(GetDate(), 'HHmmss'));
DECLARE @SUM_HOUR varchar (10);
SET @SUM_HOUR = (CAST(@ACTUAL_DATE as int)) 2;
DECLARE @NEXT_HOUR VARCHAR (46);
SET @NEXT_HOUR = (SELECT Hr_Proxima_Transmissao FROM TBJDCTC_AGENDA_TRANSMISSAO WHERE Arquivo_TP = 'ACTC101');
PRINT @ACTUAL_DATE;
PRINT @SUM_HOUR;
PRINT @NEXT_HOUR;
Could anyone help?
CodePudding user response:
You are looking for the DATEADD
function. You can add 2 seconds to a DATE
like so
DATEADD(second,2,@ACTUEL_DATE)
CodePudding user response:
I got it with the following command:
DECLARE @SOMAHORA VARCHAR (30);
SET @SOMAHORA = REPLACE(CONVERT(varchar, DATEADD(SECOND, 2, GetDate()), 24), ':', '');