April 8, 2013 at 7:42 pm
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
April 8, 2013 at 8:11 pm
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)
April 9, 2013 at 3:22 am
Thanks so much for help. it worked.
Kind Regards
Dhananjay
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply