14 04 2010
SharePoint – "New" Image Graphic – Identify New Content to Users
If you’re displaying a list of items in a Data View Web Part, you might want to visually show to your users if the item displayed is a “new” item. An extra little flourish to enhance the user experience.
Let us first decide that a item should be flagged as “new” if it was created within the past 7 days (though for busier lists, you might want to reduce that down to a couple of days, or even hours!).
Select the field in our DVWP that you want to show the new icon and jump back to Code View. Find the value-of statement which prints this.
Just after the value-of statement, create an if statement to find out if this item was Created in the past 7 days, and if so, display the new icon from the 12-hive layouts library.
<xsl:if test="(ddwrt:FormatDateTime(string(ddwrt:Today()),2057,'yyyMMdd') - ddwrt:FormatDateTime(string(@Created),2057,'yyyMMdd')) < 7"><br><img alt="New Item" src="/_layouts/1033/images/new.gif" style="border: 0;" title="New Item" /><br></xsl:if><br><br>
The essence behind our if test is simply convert “Today()” into a number composing of yyyymmdd (so today would be 20100414 and do the same with the list item’s Created date (like 20100410), subtract the latter from the former and see if we get a number less than 7.
As raised by Marc Anderson in the comments for this post, this method may introduce odd behaviour at month end boundaries. His blog post suggests using the ddwrt-namespace method “IfNew” (which I didn’t know until I read that! Learn something new every day!) which uses server-set variable 2 days for new items (which can be changed). The method in his blog post is definitely more concise and easier to read. You may want differing definitions of “New” in different lists throughout your site – so the method in this post may be a starting point for doing so.
A good point was raised by Brian on the community support website “SharePoint Overflow“:
This looks like it will work. A side note, you must be careful about the RegionalSettings for the web and how the SPListItem returns it’s “Created” (and also “Modified”) fields. Comparing them to DateTime.Now is probably not valid if your site is accessed by users not in the TimeZone specified for the SPWeb. See this: msdn.microsoft.com/en-us/library/ms197282.aspx and this http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.aspx.
Taken from the question thread found at: http://www.sharepointoverflow.com/questions/5322/splistitem-isnew-functionality