简体   繁体   中英

How do I compare two dates in Sharepoint listview with javascript?

I want to compare two dates in a sharepoint list using javascript. 2 years ago I asked a question about comparing two dates in sharepoint. The code I use is this:

var date = new Date(listItem.LTIOV);
var todaysDate = new Date();

if ((date < todaysDate) && (listItem.MijnStatus == "In Action")) {
    if (row != null){
        row.style.backgroundColor = "rgba(153, 204, 255, 0.5)"; //light blue
    }
}

Back then is worked because the date in listitem.LTIOV was only a date and no time. This time my date also has a time part in it. I already tried with date.GetTime() but the results are not correct. Some dates come back with a year in the future like 2022.

Anyone know how to do this?

Marco

The new Date(listItem.LTIOV) would also get the time, if you don't have time in listitem.LTIOV, it would return as in 00:00:00 for the time.

So, you could compare two dates with time like this:

var date = new Date(date1);
var date = new Date(date2);
if(date1<date2){

}

Reference:

https://www.w3schools.com/js/js_date_methods.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM