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)
 Get time before current time

Author  Topic 

ayamas
Aged Yak Warrior

552 Posts

Posted - 2008-04-16 : 13:31:48
Hi guys,

I dont know whether this question sounds silly.I came up with a situation where I need to know what was the time 30 minutes before the current time.
Is there any straightforward way to get it..?
Regards

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-04-16 : 13:35:33
select dateadd(n, -30, getdate())

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2008-04-16 : 13:40:36
quote:
Originally posted by spirit1

select dateadd(n, -30, getdate())

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com



That was really a quick answer.Thanks.
Can I know why select datediff(n,-30, getdate()) this does not work.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-04-16 : 13:43:48
because datediff returns a difference between 2 datetimes in the unit you provide as the first parameter

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-16 : 13:45:30
the second argument of datediff should be a datetime value. Look for syntax and explanation in BOL. It actually provides the diffrence in units specified by first argument between the secong argument date value and third argument date value.
Go to Top of Page
   

- Advertisement -