Well, why would you do that? That was actually a question on the SharePoint forums and it boils down to calculating date differences which is not well supported as one may think. Calculating the number of days from a certain date till the current date can be useful – you may want to determine the birthdays or how old a person is if their date of birth is in a list or even just flagging items that have been added or updated in the past n days.
There are some tricks working around using [Today] in calculated columns (which is not allowed), but these may not work or require other steps to keep [Today] current (like updating all list items to trigger it to change).
The answer is in the XSL. In fact, since dataforms support adding a formula as a column, I will use that feature.
Create a web part page and add a data form to it (insert Data View / Empty Data View). Select your list or library as the source and select a few fields from the source and choose to insert selected fields as Multiple Item view. Choose Add/Remove columns to customize the list and add a Formula column to the list (last item). You will be prompted to construct the formula. Here, we count the number of days since a list item was created and here’s the formula:
((substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),7,2)) + floor((153 * ((substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),5,2)) + 12 * (floor((14 – (substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),5,2))) div 12)) – 3) + 2) div 5) + ((substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),5,2))) div 12))) * 365 + floor(((substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),5,2))) div 12))) div 4) – floor(((substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),5,2))) div 12))) div 100) + floor(((substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),5,2))) div 12))) div 400) – 32045) – ((substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),7,2)) + floor((153 * ((substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),5,2)) + 12 * (floor((14 – (substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),5,2))) div 12)) – 3) + 2) div 5) + ((substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),5,2))) div 12))) * 365 + floor(((substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),5,2))) div 12))) div 4) – floor(((substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),5,2))) div 12))) div 100) + floor(((substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),5,2))) div 12))) div 400) – 32045)
This is actually based on the great work from a blog by Mark Kruger (the xsl way is more user friendly to read, of course). The formula subtracts the creation date from today’s date and involves converting dates to Julian. Once you close the formula, it will have an ugly header which you can replace with your own.
Note: make sure you use regular single and double quotes if you copy the formula and end up with tidy quotes (those with curly end).