Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Comapring Date in share point 2010 - problems using less than or greater than

Posted on 2013-01-07
6
Medium Priority
?
641 Views
Last Modified: 2013-01-19
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
<xsl:param name="dvt_apos">&apos;</xsl:param>

Open in new window

I inserted
<xsl:param name="Today" />

Open in new window

This automatically generated
<ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>

Open in new window

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,' '),'-','') &lt; translate(substring-before(@Created,' '),'-','')">
			<span class="Ms-NewIcon"><xsl:text> !New</xsl:text></span>
		</xsl:when>
				
	</xsl:choose>
</li></ul></td></tr>

Open in new window

0
Comment
Question by:CptO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 15

Expert Comment

by:sharepointguru14
ID: 38757711
do you want this 2 day new to be 7 days for just a particular list view or you would like it for the web app? You can change the value with stsadm
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.
0
 

Author Comment

by:CptO
ID: 38759651
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 (&gt; or &lt;) do not, with no error message Example:
These two work:
<xsl:if test="substring-before(@Modified,'T') = substring-before(@Created,'T')"
<xsl:if test="substring-before(@Modified,'T') != substring-before(@Created,'T')">

These Two do not:
<xsl:if test="substring-before(@Modified,'T') &gt; substring-before(@Created,'T')">
<xsl:if test="substring-before(@Modified,'T') &lt; substring-before(@Created,'T')">
0
 

Author Comment

by:CptO
ID: 38760830
Update - If I create a calculated column in the library, and use the equation

=IF(Created+7>=TODAY(),"!New",IF(Modified+7>=TODAY(),"!Updated",""))

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.
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 15

Expert Comment

by:sharepointguru14
ID: 38761512
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(string(@Modified), number(1033),1)&lt;=ddwrt:FormatDate(string(@Created), number(1033), 1)">
0
 

Accepted Solution

by:
CptO earned 0 total points
ID: 38775413
Please note I am a power user, not a professional developer, so use anything in this post at your own risk and test test test.

Sharepoint guru - same issue. It only works for the equal or not equal operators. Apparently this is because SPD / SP sucks at doing date comparisons, probably because dates are not base 10 and Microsoft just did not build any documented functions to do it in SharePoint Designer. That is really strange as a calculated column in a document library will work
=IF(Created+7>=TODAY(),"!New",IF(Modified+7>=TODAY(),"!Updated","")) 

Open in new window

.

A developer answered with a working solution in the MSDN Sharepoint develeopers forum Using Greater than or Less than for date comparison in Sharepoint Designer

My original code should never have worked at all. It only did so by pure chance. the code converted dates into the YYYYMMDD format. If your date added or subtracted  was less than 31 days it works, once you go over  30 - 31 days it fails. Try it and see. 20121201 (12-1-2012)  + 31 = 20121232 (not a date) If it worked correctly I would expect 20130101 (1-1-2013)

The working code suggested is below. It converts the times into the number of seconds since a date hard coded in the program. All operators work, and I have compared it on dates up to 395 days apart and it worked. Information on the undocumnented "ddwrt:DateTimeTick" can be found at ddwrt:DateTimeTick -Marc D anderson, MVP

Note a couple of things - As mentioned in the article, this will give the incorrect result in SharePoint Designer, but it will give the correct result on the browser. This is due to the different beginning dates used by Sharepoint and the browser (Good one Microsoft). also note that they use the $Today variable to calculate today, which  requires @Today to be declared in the webpart, instead of "TodayIso()", which should be easier...As long as you rememebr "Please note I am a power user not a sharepoint developer..." and test.

<xsl:choose>
	<xsl:when test="(number(ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(@Created)))) - number(ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(ddwrt:TodayIso()))))) div 864000000000 +7 &gt;= 0">
		<span class="Ms-NewIcon"><xsl:text> !New</xsl:text></span>
	</xsl:when>
	<xsl:when test="(number(ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(@Modified)))) - number(ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(ddwrt:TodayIso()))))) div 864000000000 +7 &gt;= 0">
		<span class="Ms-NewIcon"><xsl:text> !Updated</xsl:text></span>
	</xsl:when>
</xsl:choose>

Open in new window



I am not sure how to close this question without marking my own post as the answer. I do not deserve the posts as someone else gave me the answer, so please forgive me if that is incorrect.
0
 

Author Closing Comment

by:CptO
ID: 38796073
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question