Date less than today

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Post Reply
User avatar
KateřinaCísařová
Posts: 2
Joined: Tue Apr 20, 2021

21 Apr 2021

Hi,

can you help me with code, please?

I need to change status if user chooses date less than today.

Thank you very much.

Katerina

User avatar
Nikita Kurguzov
Posts: 856
Joined: Mon Jul 03, 2017

04 May 2021

Replied in the other topic, but just in case, the following JS code should work:

Code: Select all

function compareDateToToday(date){
  var q = new Date();
  var m = q.getMonth();
  var d = q.getDate();
  var y = q.getFullYear();

  var today = new Date(y,m,d);
  if(today>date){
    alert("Date is before today");
  }
  else if (today<date){
    alert("Date is after today")
  }
  else{
    alert("Date is today");
  }
}

fd.field('Date').change(function(){
  var date = new Date(fd.field('Date').value());
  compareDateToToday(date);
});
Of course, it might need some adjustments to your case, so if you have any issues - please, post a screenshot of a form with console errors that you get!
Cheers

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests