Mihir
Mihir

Reputation: 8734

how to compare the date in xml row with today's date

I have one xml file which is retrieved using jquery in sharepoint. One of the row of the xml is like below.

<z:row ows_Title='Have dinner party with Host' ows_Due_x0020_Date='2012-05-10 00:00:00' ows_MetaInfo='1;#' ows__ModerationStatus='0' ows__Level='1' ows_ID='1' ows_UniqueId='1;#{2A8F277A-C95B-420C-89A9-3B979F95C8F4}' ows_owshiddenversion='3' ows_FSObjType='1;#0' ows_Created='2012-10-25 03:19:35' ows_PermMask='0x7fffffffffffffff' ows_Modified='2012-10-29 00:56:09' ows_FileRef='1;#personal/Inclusions/Lists/Events/1_.000' />

Now i want to retireve the "Due Date" column and compare with the today's date. For retrieving date there is no issue. But how to compare the both dates? For comparing the date with today I used like this.

    var k = new Date();
    var year = k.getYear();
    var month = k.getMonth();
    var day = k.getDate();
    var fulldate = year+"-"+month+"-"+day

But it is displaying only with date. In xml we are getting time also. I dont want to compare with time. I want to compare with only dates. How to achieve it? I want to put that whole process in the following function.

$(xData.responseXML).find("z\\:row").each(function() { 
          //here i want to compare that date column with present date

});

Finally i want, the date coming in the xml is less than the today's date or not?

Upvotes: 0

Views: 1085

Answers (3)

charlietfl
charlietfl

Reputation: 171679

Highly recommend Date.js library for all the comparison and formatting methods that can make a lot of date work greatly simplified

http://www.datejs.com/

Upvotes: 1

Mihir
Mihir

Reputation: 8734

finally the required comparison like below.

function compareDates(passdate)
    {   
        var splitdate = passdate.split(" ");
        var splitdate1 = splitdate[0].split("-");
        var newdate = splitdate1[1]+"-"+ splitdate1[2]+"-"+splitdate1[0];
        return ((Date.parse(newdate)) < (new Date()).getTime());
    }

Upvotes: 0

elclanrs
elclanrs

Reputation: 94101

Something like this:

function isPastDate( date ) {
  return (new Date( date )).getTime() < (new Date()).getTime();
}

Upvotes: 1

Related Questions