October 11, 2005 at 4:05 am
A quick question .
How do I deduct 60 minutes fro a date?
for eg: if my getdate() returns 2005-10-11 10:37:35.153 then I need the out put as
2005-10-11 09:37:35.153
October 11, 2005 at 5:02 am
Either
SELECT DATEADD(mi,-60,GETDATE())
or
SELECT DATEADD(hh,-1,GETDATE())
First subtracts 60 minutes, second subtracts 1 hour.
HTH
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
October 11, 2005 at 5:45 am
Thank you very much.
Can we use datediff?
Rajesh
October 11, 2005 at 6:05 am
Not for what you're trying to do.
From Books Online:
The DATEADD function adds an interval to a date you specify.
The DATEDIFF function calculates the amount of time in dateparts between the second and first of two dates you specify. In other words, it finds an interval between two dates.
ie. use DATEADD to add a certain number of intervals (eg. hours, days, years) to a date, use DATEDIFF to calculate the number of intervals (eg. hours, days, years) between two dates.
Run the following for an example
SELECT DATEDIFF(dd,'2005/10/01','2005/10/30') AS DateDifference, DATEADD(dd,25,'2005/10/01') DateAdded
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply