SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Subtract Two DateTime Columns And Get Minutes
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

uneek78
Starting Member

13 Posts

Posted - 12/18/2012 :  13:31:48  Show Profile  Reply with Quote
I have the following:

SELECT ExplorerSnapshot.SignerLastName, ExplorerSnapshot.SignerFirstName,
ExplorerSnapshot.DictatorLastName, ExplorerSnapshot.DictatorFirstName,
"dbo"."Order".CreateDate, "dbo"."Order".CompleteDate,
Report.BeginEditDate, Report.LastPrelimDate,
Report.LastSignDate, Report.IsAddendum

FROM "dbo"."Order", ExplorerSnapshot, Report

WHERE Report.ReportID = "dbo"."Order".ReportID
AND ExplorerSnapshot.ReportID = "dbo"."Order".ReportID
AND ExplorerSnapshot.OrderDate BETWEEN '12/15/2012' and '12/18/2012'
;

My goal is to have:

Report.LastSignDate subtract from Report.LastPrelimDate and give minutes

Report.LastPrelimDate subtract from Report.BeginEditDate and give minutes

Report.BeginEditDate subtract from "dbo"."Order".CompleteDate and give minutes

"dbo"."Order".CompleteDate subtract from "dbo"."Order".CreateDate and give minutes


Is that possible?

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/18/2012 :  13:49:07  Show Profile  Reply with Quote
You can add columns such as shown below:
....
Report.BeginEditDate, Report.LastPrelimDate,
Report.LastSignDate, Report.IsAddendum,
DATEDIFF(minute, Report.LastPrelimDate, Report.LastSignDate),
DATEDIFF(minute, Report.LastPrelimDate, Report.BeginEditDate)

FROM "dbo"."Order", ExplorerSnapshot, Report
...
Go to Top of Page

uneek78
Starting Member

13 Posts

Posted - 12/18/2012 :  16:28:17  Show Profile  Reply with Quote
THANK YOU!!!!! You're a genius and it worked!!!! Of all the hours of googling and I got nothing that worked. Yours worked! THANKS!!!!
Go to Top of Page

uneek78
Starting Member

13 Posts

Posted - 12/18/2012 :  16:29:57  Show Profile  Reply with Quote
Soooooooooooooooooo(lol) how could I give each of those columns a specific name?
Go to Top of Page

Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1600 Posts

Posted - 12/18/2012 :  19:51:57  Show Profile  Reply with Quote
Give each one an alias:
DATEDIFF(minute, Report.LastPrelimDate, Report.LastSignDate) as MinutesToSign,
DATEDIFF(minute, Report.LastPrelimDate, Report.BeginEditDate) as MinutesTostart



=================================================
Hear the sledges with the bells - silver bells!
What a world of merriment their melody foretells!

Edited by - Bustaz Kool on 12/18/2012 19:52:49
Go to Top of Page

uneek78
Starting Member

13 Posts

Posted - 12/19/2012 :  09:48:25  Show Profile  Reply with Quote
Aaaaaah..........much appreciated my friend.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 12/19/2012 :  09:55:44  Show Profile  Reply with Quote
quote:
Originally posted by uneek78

Aaaaaah..........much appreciated my friend.



see this to understand how date operations are done in t-sql

http://visakhm.blogspot.in/2012/07/generate-datetime-values-from-integers.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000