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 2005 Forums
 Transact-SQL (2005)
 simplify this date function

Author  Topic 

djorre
Yak Posting Veteran

94 Posts

Posted - 2009-07-29 : 09:21:49
Hi,

After a lot of struggling I managed to get a query work for a certain application, but it looks like mess. Can someone simplifie this please?

SELECT xx
FROM xx WHERE xx and
[timestep] =
cast(getdate() -
cast(datepart(hour,getdate()) as float)/24 -
cast(datepart(minute,getdate()) as float)/(24*60) -
cast(datepart(second,getdate()) as float)/(24*60*60) -
cast(datepart(millisecond,getdate()) as float)/(24*60*60*1000) +
cast(@timestep as float)/(24*60*60)
as datetime)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-29 : 09:34:05
[code]select dateadd(second, @timestep, dateadd(day, datediff(day, 0, getdate()), 0))[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

ddramireddy
Yak Posting Veteran

81 Posts

Posted - 2009-07-29 : 09:39:45
Khtan,
I think this is enough?
select dateadd(second,3, datediff(dd, 0, getdate()))

is there any reason we need another dateadd function in third argument?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-29 : 09:50:56
quote:
Originally posted by ddramireddy

Khtan,
I think this is enough?
select dateadd(second,3, datediff(dd, 0, getdate()))

is there any reason we need another dateadd function in third argument?



Yes. if this is what OP wanted.

No. Not really, . . maybe lack of ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

djorre
Yak Posting Veteran

94 Posts

Posted - 2009-07-29 : 09:55:00
[timestep] = dateadd(second,@timestep, datediff(dd, 0, getdate()))

yes this works thank you very much!
Go to Top of Page
   

- Advertisement -