In a table that I have, I have a date field that indicates the date an order was placed. I would like to create a calculated field in my datapage that will indicate how long it has been since the order was open (that is, the difference between today's date and the order creation date). Is there any way to do this? I know it will involve Datediff but I am unsure of how to insert today's date automatically.
Order Created - 1/20/16
Today's Date - 2/12/16
The expected output would be 23.
EDIT: So I've implemented this using the following formula: DATEDIFF(day,OrderDate, GETUTCDATE()) and it works correctly but now I need this to ONLY count business days (at the moment, it is counting weekends as well).
EDIT 2: I've figured it out. I will leave the answer here for posterity:
To calculate the difference in dates (only considering business days), enter the following into your calculated field:
select (DATEDIFF(dd,@StartDate, @EndDate))
- (DATEDIFF(ww,@StartDate, DATEADD(dd,-1,@EndDate)) * 2)
- (CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 else 0 end)
- (CASE WHEN DATENAME(dw, @EndDate) = 'Sunday' THEN 1 else 0 end)
where you replace @StartDate and @EndDate with your corresponding fields (if you're calculating days from today, then use GETUTCDATE() for @EndDate).