5
Answers

How to compare current date with ModifiedDate in SPlist

I am looking for a solution :
Only for if condition to read first row's modified date and compare it current date [ ex today =21/01/2016 ]
condition :
if [ first row's Modified date == current date (Today)]
{
I have to do nothing
}
else
{
I will run my existing javascript to update all items
}
 
 
 Javascript :
var clientContext = null;
var globalCount = 0;
var itemCountList = 0;
var curentDate = new Date();
function uploadDest(){
clientContext = new SP.ClientContext("");
oList = clientContext.get_web().get_lists().getByTitle("");

camlQuery1 = new SP.CamlQuery();
query1 ='<View></View>';
camlQuery1.set_viewXml(query1);
this.collListItems1 = oList.getItems(camlQuery1);

clientContext.load(collListItems1);

clientContext.executeQueryAsync(Function.createDelegate(this, this.onMultiSelectListDataLoadQuerySucceeded1), Function.createDelegate(this, this.onMultiSelectListDataLoadQueryFailed));
}
function onMultiSelectListDataLoadQuerySucceeded1(sender, args){

listItemEnumerator1 = collListItems1.getEnumerator();
itemCountList = collListItems1.get_count();
while (listItemEnumerator1.moveNext()) {
oListItem1 = listItemEnumerator1.get_current();
oListItem1.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

}

}
function onMultiSelectListDataLoadQueryFailed(){
alert("error occured");
}
function onQuerySucceeded() {
globalCount = globalCount + 1;
console.log("success / "+ globalCount + "/" + itemCountList);
if(globalCount==itemCountList){
localStorage.setItem("code","1");
window.location = document.location.href;
location.reload();
}

}
function onQueryFailed(sender, args) {
console.log("error");
}
if(localStorage.getItem("code") === null){
ExecuteOrDelayUntilScriptLoaded(function(){
var div = document.getElementById("WebPartWPQ2");
div.style.opacity = 0;
uploadDest();

},"sp.js");
}else{
localStorage.removeItem("code");
}
}
</script>
 

Answers (5)

1
Photo of Raja T
NA 7.4k 6k 9y
Hello Payal , Refer below code
 
 
<script type="text/javascript" language="javascript"> 
function isGreater(date)
{ 
   if(this.getTime() > date.getTime())
   { 
      return true;
    } 
   else
   {    return false;
    }
 } 

Date.prototype.IsGreater = isGreater; //dd/MM/yyyy 
// Clearly instantiate a Date object with params as per your textboxes 
var dateOne = new Date();  
 dateOne.setFullYear(2001,12,31); // 31st December 2001 
var dateTwo = new Date(); 
 dateTwo.setFullYear(2002,1,1); // 1st Jan 2002     
 alert("Date Two is greater : " + dateTwo.IsGreater(dateOne));
 alert("Date One is greater : " + dateOne.IsGreater(dateTwo)); //I would use a custom validator with a function based on the above. 

</script>

Please refer below links 

http://stackoverflow.com/questions/7335075/compare-2-dates-in-format-dd-mm-yyyy-with-javascript-jquery
https://bytes.com/topic/javascript/answers/485296-dd-mm-yyyy-date-compare-problem
http://forums.asp.net/t/1096556.aspx

 
0
Photo of Payal Banerjee
NA 11 345 9y
thnk u for resolution. But I have mentioned issue in your reply.Plz check and let me know , if u can help ....
0
Photo of Payal Banerjee
NA 11 345 9y
thnk u for resolution. But I have mentioned issue in your reply.Plz check and let me know , if u can help ....
0
Photo of Payal Banerjee
NA 11 345 9y
thnk u for resolution. But I have mentioned issue in your reply.Plz check and let me know , if u can help ....
0
Photo of Payal Banerjee
NA 11 345 9y
Thank you so much for the fast resolution.
Actually , what I am looking for is : to compare current date=Today with aSharepoint list 's first item's Modified date.
 
So, I am not able to read that Sharepoint list's first item 's Modified date. 
So I want to add that if condition :
Current date == Modified date of 1st item in sharepoint list
then if condition fails
{
 
update list with :
 
listItemEnumerator1 = collListItems1.getEnumerator();
itemCountList = collListItems1.get_count();
while (listItemEnumerator1.moveNext()) {
oListItem1 = listItemEnumerator1.get_current();
oListItem1.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));