SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Need help with Dates


Need help with Dates

Author
Message
dhananjay.nagarkar
dhananjay.nagarkar
SSC-Enthusiastic
SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)

Group: General Forum Members
Points: 120 Visits: 185
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
Mansfield
Mansfield
SSC-Addicted
SSC-Addicted (426 reputation)SSC-Addicted (426 reputation)SSC-Addicted (426 reputation)SSC-Addicted (426 reputation)SSC-Addicted (426 reputation)SSC-Addicted (426 reputation)SSC-Addicted (426 reputation)SSC-Addicted (426 reputation)

Group: General Forum Members
Points: 426 Visits: 394
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)


dhananjay.nagarkar
dhananjay.nagarkar
SSC-Enthusiastic
SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)

Group: General Forum Members
Points: 120 Visits: 185
Thanks so much for help. it worked.

Kind Regards
Dhananjay
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search