1,804 articles and 14,931 comments as of Wednesday, May 18th, 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
Wednesday, October 14, 2009

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

Overview

In continuance of the series on the “Date and Time” set of functions that I wrote about back at the end of May (that darn “Work” always getting in the way), I’d like to discuss the actual “DATE” function itself in order to help address some of the more frequent questions regarding how to deal with dates in SharePoint.

The Function

DATE: this returns the “sequential” serial number that represents a specific date.

It’s syntax is:
=DATE(year,month,day)

year” represents a value between 0 and 9999
month” represents a value between 1 and 12
day” represents a value between 1 and 31

Given the above, this would mean that its usage could be something as simple as:

=DATE(1971,9,15)

This will return the serial number of “26,191(as a side-note: can anyone guess the significance of the date I’m using for this example?).
In SharePoint, all dates are stored as serial numbers in order to make it easier (subjective term) to use them in calculations.  The reason it winds up being easier is because it places the date value in a standard format that separates it from any formatting rules applied by localization (U.S. date format vs. European vs. Australian, etc.). 

In a way, you could think of it as the perfect example of separating “Presentation” from “Content” – the data is in a truly universal format that can be used in any calculation needed, then “formatted” back into a friendly display that adheres to any needed localization rules.

Tools of the Trade

Looking at the serial number itself, we can validate its accuracy by performing some simple math (another subjective term) based on the date that SharePoint uses as the starting point (December 31, 1899), or if you’re like me and hate math (that’s why I work with computers – it has a calculator on it), you can find the number of days between two dates by using a service on “time and date.com” (http://www.timeanddate.com/date/duration.html).

Date and Time Part 5

Simply enter in our start date of “December 31, 1899” (the SharePoint date serial number of “1”), and our end date of “September 15, 1971” then click “Calculate duration” (make sure and select the “include end date in calculation” or else we’ll be off by one).

Date and Time Part 5

Of course it’s not a SharePoint resource itself, but it does validate that our result was accurate, and I always wind up using various tools online to assist me in my work, and this is a great one for working with dates to make sure we’re getting the results we should.

One thing I do want to point out though in how SharePoint actually deals with dates is that if you’re working with a year value that is less than 1899 (anywhere in between 0 and 1899), the year value will actually be itself plus 1900.  So if the year value is 12, it will actually be 1912 since the first serial number that SharePoint will be able to use is based on 1899 (1899 will equate to a serial number of 1, so 12 will become 1912, which will equate to a serial number of 13).  Although this can appear confusing, as long as you remember that the first year SharePoint can use as its starting point will always be 1899 and that you will have to add any year before it to 1900 (the year + 1900), things will turn out fine.

The next step is to move this into SharePoint to make sure that what we have on paper (and on our newly discovered helper utility on the web) will produce the same results.

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

5 Responses to “Taming the Elusive “Calculated Column” – Date and Time – Part 5”
  1. Charlie Epes says:

    Hi Dessie:
    Sorry to piggyback on this column but I found a way to use a Multiple Choice field (”Checkboxes -allow multiple selections”) in a formula! I’m using the “Today” trick.

    I created a [MultChoice] Field with Drop-Down. I then created a calc field pointing to [MultChoice].

    Then I deleted the [MultChoice] and recreated it, this time using “Checkboxes -allow multiple selections”. It works!

    Thanks to you!

    Charlie Epes
    Buffalo, NY

  2. Charlie Epes says:

    My apologies Dessie!

    I did not see your previous post at http://www.endusersharepoint.com/2009/06/17/taming-the-elusive-%e2%80%9ccalculated-column%e2%80%9d-referencing-multiple-lines-of-text-column/ in which you outline basically the same thing.

    Charlie Epes

  3. Troy Carroll says:

    I am having a devil of a time with a formula I know I’ve used several times in the past. I have two columns with times in them: Start and End.

    To calculate the hours and minutes difference between the two, I’m using
    =TEXT([End]-[Start],”h:mm”)

    So if End contains 11:30 and Start contains 8:30, I’m expecting to see 3:00 as the difference. Instead I’m getting the dreaded “The formula contains reference(s) to field(s).”

    Anyone got any pointers on this?
    Thanks in advance,
    Troy

  4. Troy,
    It appears like it should be working as expected.

    I just created a test list with two Date and Time columns (”Start”, and “End”), set a calculated column with your formula above

    =TEXT(End-Start,”h:mm”)

    and it worked just fine.

    One thing I’ve noticed on occasion that may (or may not) have something to do with it is if you copy/pasted the formula in instead of typing it – sometimes depending on the font of where you copied it from, it wont recognize the quotes.

    Maybe try manually typing it in from scratch and see if that fixes it.

    Post back with what happens,

    - Dessie

  5. Inprise says:

    Hi,

    I am new to share point and seeing many of your post,hope i might have missed your explanation as well,i just want to know how to handle current date and time + 24 hrs ,how to handle this as calculated value,i tried [Today]+1 which is not taking time for consideration .

    Please guide me


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!