• 0

# Calculating Difference In Dates

## Question

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.

Ex.

Order Created - 1/20/16

Today's Date - 2/12/16

The expected output would be 23.

Thank you.

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))
- (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).

## Recommended Posts

• 0

Hi mmorales,

Thank you for sharing the solution!

Does the query exclude only Sundays?

##### Share on other sites

• 0

Hi all,

I found a similar post about calculating dates excluding weekends. You may visit this link for more details.

-kristina

##### Share on other sites

• 0

Hello!

Here's another post that calculates number of working days excluding weekends and holidays using Application Tasks:

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.