CptO
asked on
Comapring Date in share point 2010 - problems using less than or greater than
Sharepoint 2010, using Sharepoint Designer 2010. I am a admitted newbie to manual coding.
I inserted a empty Data View Web Part ( DVWP ) and linked it to a list. I displayed the title as the only column. I then added a "when" statement to compare the @Modified date to the @Created date. Based on the results I would add text after the title. The intent is to display "New" in a column if a entry in the list was created less than 7 days ago (as opposed to the OOTB 2 days), or display "update" of it was modifiedin the last 7 days. currently I am using just one When statement for testing.
This worked in 2007. I did some modfications in 2010, necessary to format the dates correctly, but even using the exact working I had in SP2007, I get the same behavior. Interestingly enough, all DVWP's migrated from SP2007 with this code still work.
Issue: If I use Equal ( "=" ) or not equal ("!=") operators, it works as expected. If I use any type of less than or greater than operator'' it does not work. Examples: ">", "<" , ">=", and "<=". No error is thrown, it just displays nothing. Below is the code I am using.
On the line following
snippet of the code I used for the WHEN statement
I inserted a empty Data View Web Part ( DVWP ) and linked it to a list. I displayed the title as the only column. I then added a "when" statement to compare the @Modified date to the @Created date. Based on the results I would add text after the title. The intent is to display "New" in a column if a entry in the list was created less than 7 days ago (as opposed to the OOTB 2 days), or display "update" of it was modifiedin the last 7 days. currently I am using just one When statement for testing.
This worked in 2007. I did some modfications in 2010, necessary to format the dates correctly, but even using the exact working I had in SP2007, I get the same behavior. Interestingly enough, all DVWP's migrated from SP2007 with this code still work.
Issue: If I use Equal ( "=" ) or not equal ("!=") operators, it works as expected. If I use any type of less than or greater than operator'' it does not work. Examples: ">", "<" , ">=", and "<=". No error is thrown, it just displays nothing. Below is the code I am using.
On the line following
<xsl:param name="dvt_apos">'</xsl:param>
I inserted
<xsl:param name="Today" />
This automatically generated
<ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
in the DVWP snippet of the code I used for the WHEN statement
<ul><li><a href="{@FileRef}"><xsl:value-of select="@Title" /></a>
<xsl:choose>
<xsl:when test="translate(substring-before(@Modified,' '),'-','') < translate(substring-before(@Created,' '),'-','')">
<span class="Ms-NewIcon"><xsl:text> !New</xsl:text></span>
</xsl:when>
</xsl:choose>
</li></ul></td></tr>
ASKER
I forget to mention that every time. I do not have administrative access to the server. I just take care of one site/ department on the server. Plus our server admnins only support OOTB functionality. Unless there is a pressing need such as security, they prefer not to make any changes. I would also like to display New or Updated depending on whether the document is new to the library or has been modified after its creation date.
I was messing around with simplifying this and using the using the <xsl:if test=""> function and get the same results. Equal and Not equal work, but any combination of Greater or Lesser than (> or <) do not, with no error message Example:
These two work:
<xsl:if test="substring-before(@Mo dified,'T' ) = substring-before(@Created, 'T')"
<xsl:if test="substring-before(@Mo dified,'T' ) != substring-before(@Created, 'T')">
These Two do not:
<xsl:if test="substring-before(@Mo dified,'T' ) > substring-before(@Created, 'T')">
<xsl:if test="substring-before(@Mo dified,'T' ) < substring-before(@Created, 'T')">
I was messing around with simplifying this and using the using the <xsl:if test=""> function and get the same results. Equal and Not equal work, but any combination of Greater or Lesser than (> or <) do not, with no error message Example:
These two work:
<xsl:if test="substring-before(@Mo
<xsl:if test="substring-before(@Mo
These Two do not:
<xsl:if test="substring-before(@Mo
<xsl:if test="substring-before(@Mo
ASKER
Update - If I create a calculated column in the library, and use the equation
=IF(Created+7>=TODAY(),"!N ew",IF(Mod ified+7>=T ODAY(),"!U pdated","" ))
It works as expected. Than you can use Greater than and less than operators and it works as expected. While this is a potential soultion, it is not ideal as it would require modifiying a LOT of libraries.
=IF(Created+7>=TODAY(),"!N
It works as expected. Than you can use Greater than and less than operators and it works as expected. While this is a potential soultion, it is not ideal as it would require modifiying a LOT of libraries.
I know it doesn't make sense since = != work but what if you formatted the date for the created and modified columns to ensure they are in the same format when comparing them. Something like this
<xsl:if test="ddwrt:FormatDate(str ing(@Modif ied), number(1033),1)<=ddwrt: FormatDate (string(@C reated), number(1033), 1)">
<xsl:if test="ddwrt:FormatDate(str
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This item is closed. I proposed my own asnwer as it is the one that is working for me. The points however should not be awarded as the amswer was given by someone else in another forum, thus it is not me who answered the question. Please see the other post at http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomizationprevious/threads/ <br /><br />There are several informative links that will give addional information on the undocumented functions in the answer.
stsadm -o setproperty -pn days-to-show-new-icon -pv 7 -URL [Server URL]
changing the value for -pv to the number of days you want it.