1,804 articles and 14,827 comments as of Tuesday, May 10th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Monday, June 1, 2009

Taming the Elusive “Calculated Column” – Date and Time – Part 3

Test, Test, and Retest (then add 1 for good measure)

We’ll be using 4 different sets of dates in order to be able to test for the full range of possibilities with our formula:

Test #1: “Same Day”
Start Date: 5/12/2009
End Date: 5/12/2009

Test #2: “No Weekend”
Start Date: 5/18/2009
End Date: 5/22/2009

Test #3: “With Weekend”
Start Date: 5/22/2009
End Date: 5/26/2009

Test #4: “Multiple Weekends”
Start Date: 5/11/2009
End Date: 5/25/2009

We’ll plug in each of the test dates above, and run through them one by one.

Test #1: “Same Day”
Start Date: 5/12/2009
End Date: 5/12/2009

Functions:

WEEKDAY([Start Date],2) = WEEKDAY(“5/12/2009”,2) = Tuesday = 2
WEEKDAY([End Date],2) = WEEKDAY(“5/12/2009”,2) = Tuesday = 2
DATEDIF(“5/12/2009”, “5/12/2009”,"D") = 0

Our “Condition” part of the “IF” becomes:

IF(AND(2<2,(2-2)>1)

Breaking this apart, our two conditions to check for:

Is 2 less than 2? (FALSE)
Is 2 minus 2 greater than 1? (FALSE)

Since both of these are False (remember, in an “AND” function both conditions must be True for the entire condition to be True), we move to the “FALSE” side of the “IF”, which by replacing its functions with our values, becomes:

(((DATEDIF(“5/12/2009”, “5/12/2009”,"D")+1))-(FLOOR((DATEDIF(“5/12/2009”, “5/12/2009”,"D")+1)/7,1)*2))

Completing some of the functions:

(((0+1))-(FLOOR((0+1)/7,1)*2))

Cleaning it up some:

(1-(FLOOR(1/7,1)*2))

And again:

(1-(FLOOR(0.14286,1)*2))

One more time:

(1-(0*2))

Finishing off the math:

(1-(0*2)) = (1-0) = 1

Result = 1 since the “Start Date” and “End Date” are both on the same day, 1 day has elapsed.

Date and Time

Test #2: “No Weekend” (both dates in same week)
Start Date: 5/18/2009
End Date: 5/22/2009

Functions:

WEEKDAY([Start Date],2) = WEEKDAY(“5/18/2009”,2) = Monday = 1
WEEKDAY([End Date],2) = WEEKDAY(“5/22/2009”,2) = Friday = 5
DATEDIF(“5/18/2009”, “5/22/2009”,"D") = 4

Our “Condition” part of the “IF” becomes:

IF(AND(5<1,(1-5)>1)

Breaking this apart, our two conditions to check for:

Is 5 less than 1? (FALSE)
Is 1 minus 5 greater than 1? (FALSE)

Since both of these are False, we move to the “FALSE” side of the “IF”, which by replacing its functions with our values, becomes:

(((DATEDIF(“5/18/2009”, “5/22/2009”,"D")+1))-(FLOOR((DATEDIF(“5/18/2009”, “5/22/2009”,"D")+1)/7,1)*2)))

Completing some of the functions:

(((4+1))-(FLOOR((4+1)/7,1)*2)))

Cleaning it up some:

(5-(FLOOR(5/7,1)*2))

And again:

(5-(FLOOR(0.71428,1)*2))

One more time:

(5-(0*2))

Finishing off the math:

(5)-(0*2)) = (5-0) = 5

Result = 5 since the “Start Date” is on Monday and “End Date” is on the Friday of the same week, 5 days have elapsed.

Date and Time

Test #3: “With Weekend” (weekend days in between start and end dates)
Start Date: 5/22/2009
End Date: 5/26/2009

Functions:

WEEKDAY([Start Date],2) = WEEKDAY(“5/22/2009”,2) = Friday = 5
WEEKDAY([End Date],2) = WEEKDAY(“5/26/2009”,2) = Tuesday = 2
DATEDIF(“5/22/2009”, “5/26/2009”,"D") = 4

Our “Condition” part of the “IF” becomes:

IF(AND(2<5,(5-2)>1)

Breaking this apart, our two conditions to check for:

Is 2 less than 5? (TRUE)
Is 5 minus 2 greater than 1? (TRUE)

Since both of these are True (in the “AND” function, all parts must evaluate to True in order for the entire check to be True), we move to the “TRUE” side of the “IF”, which by replacing its functions with our values, becomes:

(((DATEDIF(“5/22/2009”, “5/26/2009”,"D")+1))-(FLOOR((DATEDIF(“5/22/2009”, “5/26/2009”,"D")+1)/7,1)*2)-2)

Completing some of the functions:

(((4+1))-(FLOOR((4+1)/7,1)*2)-2)

Cleaning it up some:

(5-(FLOOR(5/7,1)*2)-2)

And again:

(5-(FLOOR(0.71428,1)*2)-2)

One more time:

(5-(0*2)-2)

Finishing off the math:

(5-0-2) = 3

Result = 3 since the “Start Date” is on Friday and “End Date” is on the Tuesday of the following week, 5 days have elapsed with 2 of them being weekend days, so we subtract 2 from the total giving us a final result of 3 (counting Friday, Monday, and Tuesday).

Date and Time

Test #4: “Multiple Weekends” (more than one set of weekends)
Start Date: 5/11/2009
End Date: 5/25/2009

Functions:

WEEKDAY([Start Date],2) = WEEKDAY(“5/11/2009”,2) = Monday = 1
WEEKDAY([End Date],2) = WEEKDAY(“5/25/2009”,2) = Monday = 1
DATEDIF(“5/11/2009”, “5/25/2009”,"D") = 14

Our “Condition” part of the “IF” becomes:

IF(AND(1<1,(1-1)>1)

Breaking this apart, our two conditions to check for:

Is 1 less than 1? (FALSE)
Is 0 greater than 1? (FALSE)

Since both of these are False, we move to the “FALSE” side of the “IF”, which by replacing its functions with our values, becomes:
(((DATEDIF(“5/11/2009”, “5/25/2009”,"D")+1))-(FLOOR((DATEDIF(“5/11/2009”, “5/25/2009”,"D")+1)/7,1)*2)))

Completing some of the functions:

(((14+1))-(FLOOR((14+1)/7,1)*2)))

Cleaning it up some:

(15-(FLOOR(15/7,1)*2)

And again:

(15-(FLOOR(2.14285,1)*2)

One more time:

(15-(2*2))

Finishing off the math:

(15-(2*2)) = (15-4) = 11

Result = 11 since the “Start Date” is on a Monday and “End Date” is also on a Monday, but two weeks later, we count the total number of days between the two (15) then subtract the number of weekend days (4) giving us a total of 11 days elapsed.

Date and Time

In the next part of this series, we’ll be wrapping things up with a quick revisit to our (now more understandable) formula, and summary.

Till then…

- Dessie

Dessie LunsfordDessie Lunsford
Points-of-Sharing

View all entries in this series: Dessie Lunsford-Logic Formulas»
Entries in this series:
  1. Taming the Elusive "Calculated Column"
  2. EndUserSharePoint.com: Taming the Elusive "Calculated Column" - Customizing a Task List
  3. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Task List (Part II)
  4. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Task List (Part III)
  5. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Task List (Part IV)
  6. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Text and Data
  7. EndUserSharePoint.com: Taming the Elusive "Calculated Column" - Customizing a Contacts List (Part I)
  8. EndUserSharePoint.com: Taming the Elusive "Calculated Column" - Customizing a Contacts List (Part II-I)
  9. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Contacts List (Part II-II)
  10. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Contacts List (Part II-III)
  11. EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Text and Data (Part III)
  12. EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Text and Data (Part IV)
  13. EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Text and Data (Part V)
  14. EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Text and Data (Part VI)
  15. Taming the Elusive “Calculated Column” – Lookup and Reference
  16. Taming the Elusive “Calculated Column” - Logic
  17. Taming the Elusive “Calculated Column” - Logic - Part 1
  18. Taming the Elusive “Calculated Column” - Logic - Part 2
  19. Taming the Elusive “Calculated Column” - Logic - Part 3
  20. Taming the Elusive “Calculated Column” - Logic - Part 4
  21. Taming the Elusive “Calculated Column” - Logic - Part 5
  22. Taming the Elusive “Calculated Column” - Logic - Part 7
  23. Taming the Elusive “Calculated Column” - Logic - Part 6
  24. Taming the Elusive “Calculated Column” - Logic - Part 8
  25. Taming the Elusive “Calculated Column” - Logic - Part 9
  26. Taming the Elusive “Calculated Column” - Logic - Part 10
  27. Taming the Elusive “Calculated Column” - Date and Time - Part 1
  28. Taming the Elusive “Calculated Column” - Date and Time - Part 2
  29. Taming the Elusive “Calculated Column” - Date and Time - Part 3
  30. Taming the Elusive “Calculated Column” - Date and Time - Part 4
  31. Taming the Elusive “Calculated Column” - Referencing Multiple Lines of Text Column
  32. Taming the Elusive “Calculated Column” – Date and Time – Part 5
  33. Taming the Elusive “Calculated Column” – Date and Time – Part 6
  34. Taming the Elusive “Calculated Column” – Date and Time – Part 7
  35. Taming the Elusive "Calculated Column" - Referencing a Multiple Lines of Text Column With Append Text: Part 1
  36. Taming the Elusive "Calculated Column" - Referencing a Multiple Lines of Text Column With Append Text: Part 2
  37. Taming the Elusive "Calculated Column" - Referencing a Multiple Lines of Text Column With Append Text: Part 3
 

Please Join the Discussion

2 Responses to “Taming the Elusive “Calculated Column” – Date and Time – Part 3”
  1. Fred says:

    Hi Dessie,

    aparently both conditions are either both TRUE or both FALSE. It should suffice to test for just one of the conditions.

  2. Paul says:

    Hi Dessie,

    Awesome blog, hope you can point out where I’m going wrong with this calculated date problem.

    I have created an end user help desk to log service calls. One of the columns in this list is DueDate. DueDate is a calculated column based on the priority assigned to the list item. The code is:

    =IF(Priority=”Very High”,(DATE(YEAR(Created),MONTH(Created),DAY(Created))+TIME(HOUR(Created)+1,MINUTE(Created),SECOND(Created))),IF(Priority=”High”,(DATE(YEAR(Created),MONTH(Created),DAY(Created))+TIME(HOUR(Created)+5,MINUTE(Created),SECOND(Created))),IF(Priority=”Medium”,(DATE(YEAR(Created),MONTH(Created),DAY(Created)+2)+TIME(HOUR(Created),MINUTE(Created),SECOND(Created))),IF(Priority=”Low”,(DATE(YEAR(Created),MONTH(Created),DAY(Created)+5)+TIME(HOUR(Created),MINUTE(Created),SECOND(Created))),0))))

    The problem I’ve noticed is that this column works perfectly when you create a new item but as soon as another column in the same item is updated or changed the DueDate field becomes something like 01/01/3800. Really annoying. I have noticed that if I go into the column settings and simply click “OK” the column gets refreshed and the DueDate calculates correctly again.

    Any Ideas?

    Cheers,

    Paul


Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!