Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Need help with Dates Expand / Collapse
Author
Message
Posted Monday, April 8, 2013 7:42 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, October 27, 2014 6:52 AM
Points: 90, Visits: 182
Dear friends,

I'm new to TSQL and need help please -

I have to Calculate a field value as Position Duration = (Work Order End Date - Work Order Start Date)/30. Round up to the next whole number.

in the DB the 2 dates are of the format-

Work Order End Date =2013-05-31 00:00:00.000
and
Work Order Start Date = 2012-12-03 00:00:00.000

Thanks
Dhananjay
Post #1440104
Posted Monday, April 8, 2013 8:11 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Sunday, October 19, 2014 3:52 PM
Points: 364, Visits: 385
Try using DATEDIFF
http://msdn.microsoft.com/en-nz/library/ms189794%28v=sql.100%29.aspx

In conjunction with ROUND
http://msdn.microsoft.com/en-us/library/ms175003%28v=sql.100%29.aspx

For example:
declare @work_order_end_date date
declare @work_order_start_date date
set @work_order_start_date = '2012-12-03'
set @work_order_end_date = '2013-05-31'

select round(datediff(d, @work_order_start_date, @work_order_end_date) / 30.0, 0)

Post #1440110
Posted Tuesday, April 9, 2013 3:22 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, October 27, 2014 6:52 AM
Points: 90, Visits: 182
Thanks so much for help. it worked.

Kind Regards
Dhananjay
Post #1440232
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse