Look at a date range and return true if todays date is within the range

NeilH2
Giga Guru

I'm trying to look at a date range (valid from - valid to) and if today's date is within the range i want it to return true

 

my code up to now:


var ifTrue = false;
var todaysdate = gs.now();

//if todays date is more than or equal to the from date and todays date is less than or equal to the to date return true

if (todaysdate >= current.u_valid_from && todaysdate <= current.u_valid_to){

   ifTrue = true;

   }

 

Logically this should work but it isn't and I was wondering if anyone knew of a better way to do it, maybe using a built in function/glide-script?

1 ACCEPTED SOLUTION

casey_stinnett
Giga Expert

This script should do it for you! I tested it and it worked for me.



var todaysdate = gs.now();


var valid_from = new GlideDateTime(current.u_valid_from);


var valid_to = new GlideDateTime(current.u_valid_to);



//if today's date is more than or equal to the from date and today's date is less than or equal to the to date, return true


var inRange = (todaysdate >= valid_from && todaysdate <= valid_to)? true: false;


if (inRange){


  //do your thing, yo


}




Did this help you?


View solution in original post

10 REPLIES 10

You can use gs.nowDateTime() to get the date and time instead of hardcoding "00:00:00" as the time if your requirements are dependent on the time as well.