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 2008 Forums
 SSIS and Import/Export (2008)
 Add Time to a Date

Author  Topic 

Brittney10
Posting Yak Master

154 Posts

Posted - 2014-06-10 : 19:21:54
I'm trying to add time to the current date to create a new derived column. A couple examples are below. (23.00, 24.00, and 25.00 are my Times that need to be added to the current date. Current date = 2014-06-10 in these examples).

23.00 + current date = 2014-06-10 23:00:00.000
24.00 + current date = 2014-06-11 00:00:00.000
25.00 + current date = 2014-06-11 01:00:00.000
etc...

Also note, I'm not concatenating values, because when I concate 25.00, for example, to the current date the new column date will not be valid.

Thanks for your help.

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-06-10 : 19:48:45
dateadd(hh,25,cast(getdate() as DATE))
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-06-11 : 04:20:16
Also see http://www.sqltopia.com/?page_id=35



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

Brittney10
Posting Yak Master

154 Posts

Posted - 2014-06-11 : 11:25:44
Thanks! I got it working using this logic. I had tried using dateadd "hh" previously, but my problem was the numeric value needed converted to int. Now it's working perfectly!
quote:
Originally posted by James K

dateadd(hh,25,cast(getdate() as DATE))

Go to Top of Page
   

- Advertisement -