Issue is that I have one value that is returned by

$(this).attr("ows_Modified"); //(Sharepoint and SPService thing)

This value seems to be string 'Fri Oct 19 2012 13:35:45 GMT+0200' need to compare it to the date object with value format like this:

var myDate = new Date();
myDate.setDate(myDate.getDate()-31);
//2012-10-19 12:14:13 

and check with one is newer. Any ideas how to do this please ?

有帮助吗?

解决方案

Parse both dates with Date.js, it will understand both formats and then you can compare them.

After importing the library you can use

date1 = Date.parse(Fri Oct 19 2012 13:35:45 GMT+0200);
date2 = Date.parse(2012-10-19 12:14:13); // or whatever date
isGreater = date1.isAfter(date2);

As gdoron stated, you don't need date.js, but it may be worth taking a look, especially if you are likely to manage weird looking date formats or make tricky operations.

其他提示

var isBigger = new Date($(this).attr("ows_Modified")) > new Date().getDate()-31;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top