If you try to create column with field type : calculated and want to use current date as part of formula , the first thing that comes up in mind is to use [Today] as SharePoint gives it as filter option while creating views. But unfortunately if you try to add ‘[Today]’ in formula, it gives error : “Calculated columns cannot contain volatile functions like Today and Me”
Same error goes when trying to use “[Me]” too.
Well, a nice trick can allow you to do this.
- Open up the List Settings page where you want this column.
Create column named “Today”. The type doesn’t matter here, so let type as “Single Line of Text” and just click “Ok”
Now create the calculated column where you need to use current date within formula and add “Today” from available columns
Once this is done, we no longer need that our own generated column “Today” so you can delete it (Although when you need to edit formula you will need this again, so either recreate this dummy Today field or make it hidden using code behind. Otherwise SharePoint will put you again on that error screen).
This will trick the SharePoint to use [Today] (current date) as part of formula.
You can apply same trick for the current user i.e. [Me] too. Create a dummy field named “Me” use it in your formula, save the calculated column, and delete that dummy “Me” field.
For calculated fields, calculated value is stored in Database when item is created at first time and doesn’t change until item is edited. So using Today doesn’t means each time you will get value re-calculated as per actual today’s date. For that it is better to use Computed column.
This trick tells how you can use Today & Me for calculated fields. Its secondary thing whether to use them or not. This totally depends upon usage of calculated field. For example you can use this in project management site for issues list, whenever new issue item is created you need to auto calculate the minimal duration and base on production push date of solution.
In Part 2 we’ll see how to use Object Model to do this, as well as using the Computed Field to create more advance formulas