- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2014 04:02 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2014 11:37 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2014 04:12 AM
Hi,
Use dateDiff() function to check this. below is the URL
GlideSystem Date and Time Functions - ServiceNow Wiki
Regards,
Hima Pallela
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2014 08:12 AM
Hi Hima
Doesn't this just give you the difference between 2 dates it doesnt tell you if todays date falls between the two?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2014 04:15 AM
Hi Neil,
I have this code on client side. Try this
var dateFormat=g_user_date_time_format; /*This will give you teh user's date format and you should compare all the 3 dates in the same format before any calculation on it */
now you can use this
compareDates(start_date, dateFormat , Today_date, dateFormat); //returns 1 if start_date comes after today
compareDates(Today_date, dateFormat , end_date, dateFormat);
Using these you can check whether today lies between the specified dates or not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2014 08:34 AM
Hi Anuarag
Is compareDates a script include on your system?
I'm not familiar with it