how to add minutes to my hours?

Hello guys

I have this code:

declare @start_time time;
declare @elapse_time time;

set @start_time =  '13:30:00'
Set @elapse_time= '00:30:00'

SELECT DATEADD(mi, @start_time, @elapse_time)

Open in new window


How is the correct form?

thanks
LVL 1
hidrauAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
The DATEADD function requires an integer for the 2nd argument so if you want to add 30 minutes to a time, this is how it should be done:
declare @start_time time;
declare @elapse_time int;

set @start_time =  '13:30:00'
Set @elapse_time= 30

SELECT DATEADD(mi, @elapse_time, @start_time)

Open in new window

0
Pawan KumarDatabase ExpertCommented:
Please use like below -

Full and tested solution for you. :)

declare @start_time time;
declare @elapse_time time;

set @start_time =  '13:30:00'
Set @elapse_time= '00:30:00'

SELECT DATEADD(SECOND,DATEDIFF(SECOND,'00:00:00',@start_time),@elapse_time) 
AS finalTime

Open in new window


OUTPUT


/*------------------------

declare @start_time time;
declare @elapse_time time;

set @start_time =  '13:30:00'
Set @elapse_time= '00:30:00'

SELECT DATEADD(SECOND,DATEDIFF(SECOND,'00:00:00',@start_time),@elapse_time) 
AS finalTime
------------------------*/
finalTime
----------------
14:00:00.0000000

(1 row(s) affected)

Open in new window

0
hidrauAuthor Commented:
ok, I understood.

If I have this value  '01:10', I should convert the value to integer and add to my dateadd.

In this case, '01:10' how could I convert the value to integer in a correct way so the result would be 70?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Pawan KumarDatabase ExpertCommented:
In that case it will be 14:40

No need to convert to INT. the function dateadd will automatically handle it.

/*------------------------

declare @start_time time;
declare @elapse_time time;

set @start_time =  '13:30:00'
Set @elapse_time= '01:10:00'

SELECT DATEADD(SECOND,DATEDIFF(SECOND,'00:00:00',@start_time),@elapse_time) AS finalTime
------------------------*/
finalTime
----------------
14:40:00.0000000

(1 row(s) affected)

Open in new window

0
Pawan KumarDatabase ExpertCommented:
edited my last comment.
0
hidrauAuthor Commented:
Pawan,

declare @PREVISAO_INICIO datetime;
declare @TEMPO_ESTIMADO  varchar(10);

set @PREVISAO_INICIO = '20171101 13:00:00'
set @TEMPO_ESTIMADO  = '001 00:30:00'   -- ddd hh:mm:ss


how to make this calc in MSSQL
0
Pawan KumarDatabase ExpertCommented:
Pls use this

/*------------------------

declare @PREVISAO_INICIO datetime;
declare @TEMPO_ESTIMADO  varchar(50);

set @PREVISAO_INICIO = '20171101 13:00:00'
set @TEMPO_ESTIMADO  = '001 00:30:00'   -- ddd hh:mm:ss

SELECT 

DATEADD(DAY , CAST(SUBSTRING(@TEMPO_ESTIMADO,0,CHARINDEX(' ',@TEMPO_ESTIMADO,0)) AS INT),   @PREVISAO_INICIO )
 +  SUBSTRING(@TEMPO_ESTIMADO,CHARINDEX(' ',@TEMPO_ESTIMADO,0)+1, LEN(@TEMPO_ESTIMADO))
------------------------*/

-----------------------
2017-11-02 13:30:00.000

(1 row(s) affected)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hidrauAuthor Commented:
Pawan, you helped me a lot.

Thank you very very much
0
hidrauAuthor Commented:
thanks a lot
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.