How can I change the output into the total hours between 2 smalldatetime data? TIF
DECLARE @.iDAY AS SmallDatetime
SET @.iDAY = '2004-08-12 10:05:00'
PRINT @.iDAY
PRINT GETDATE()
PRINT GETDATE()-@.iDAY
+++++++++++++++
Aug 12 2004 10:05AM
Aug 13 2004 10:05AM
Jan 2 1900 12:00AM <-- I want to get the total hours (i.e. 24)I'd use:SELECT DateDiff(minute, '2004-08-12 10:05', '2004-08-13 10:05') / 60-PatP|||Thanks. That did the trick.
I found out that I can also use this one instead.
PRINT DATEDIFF(hour,GETDATE(),@.iDAY)|||I don't think that using hour will give you what you want, although it might. Using hour will return the number of hour boundaries crossed, which isn't what I think you want. Consider the case of:SELECT DateDiff(minute, '2004-08-12 10:55', '2004-08-13 10:05') / 60
, DateDiff(hour, '2004-08-12 10:55', '2004-08-13 10:05')-PatP|||It looks OK. It's rounding off giving me a minor difference but I'm not really particular with exact figures.
Thanks again.
DECLARE @.iDAY AS SmallDatetime
SET @.iDAY = '2004-08-12 11:34:00'
PRINT @.iDAY
PRINT GETDATE()
PRINT DATEDIFF(minute,GETDATE(),@.iDAY)/60
PRINT DATEDIFF(hour,GETDATE(),@.iDAY)
**** RESULTS ****
Aug 12 2004 11:34AM
Aug 17 2004 10:32AM
-118
-119
Thursday, March 8, 2012
Change to "Total Hours" Difference
Labels:
2004-08-12,
database,
iday,
microsoft,
mysql,
oracle,
output,
server,
smalldatetime,
smalldatetimeset,
sql,
tifdeclare,
total
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment