Posts Tagged ‘NOW()’

Setting The Default Value Of A DateTime Column

September 3rd, 2011 Abed Khooli 2 comments

This is a very brief post that addresses the calculated default value of a SharePoint 2010 column. There is a difference between a calculated column (you set the column type to: Calculated (calculation based on other columns)) and a calculated default value (additional column settings: default value). In the latter case, you can use volatile tokens like Today or Me – since they are used only once to initialize the column value. Volatile values should not be used for calculated columns.
So, if we have a column whose type is DateTime and we do need to keep both date and time, and also need to initialize it with current date (including time), the interface will not be very helpful. You can set the default value to Today’s Date but that will not get the time accurately.  It turns out that the Calculated Value option accepts the familiar Now() function. So, just select calculated value and type = NOW() as the formula. In a new form, the date and time controls will be filled automatically with current date and time (to the nearest minute).
If you have access to InfoPath and the list can be customized, you can easily set the default value for the date control (it will also use the Now() function).
Notice that the default value (or whatever is saved in the column) does not change (automatically) if you edit the item later (as opposed to using volatile functions in a calculated column).

Categories: Lists Tags: calculated default value,