Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 addimg mins to datetime column

Author  Topic 

Muj9
Yak Posting Veteran

75 Posts

Posted - 2014-09-09 : 09:25:31
Hi All,

I have a Column 1 datetime and and column 2 int. i want to make a thrid column, column 3 datetime based on column 1 and Column 2.


column 1 Column 2
2014-09-09 00:03:00.000 30


Expected Result
column 1 Column 2 column 3
2014-09-09 00:03:00.000 30 2014-09-09 00:03:30.000


Can Somebody help.
thank you

MichaelJSQL
Constraint Violating Yak Guru

252 Posts

Posted - 2014-09-09 : 09:41:17
DATEADD(mi,[Column 2],[column 1]) AS [column 3]
Go to Top of Page

Muj9
Yak Posting Veteran

75 Posts

Posted - 2014-09-09 : 09:45:14
Hi Thankyou for replying but i am getting the result below which is not correct.



[column 1] [column 2] [column 3]



2014-09-09 00:03:00.000 30 2014-09-09 00:33:00.000

I have checked the other columns and yes this works but one record showen above is incorrect why is this the case.

Thank you
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2014-09-09 : 14:42:49
That looks correct to me - you have 00:03, adding 30 minutes will be 00:33.
Go to Top of Page
   

- Advertisement -