The CreatorCon Call for Content is officially open! Get started here.

Query for date 30 days from now

Not applicable

I am trying to schedule a job that checks for knowledge articles within 30 days of their "valid to" date and then generates an event if that is true.

'valid_to' is a glide_date field in a knowledge record. I'm having trouble getting the query right for retrieving knowledge recrods where the valid_to date is 30 days from the current date:

var gr = new GlideRecord('kb_knowledge');
gr.addQuery('valid_to', '>=', gs.nowDateTime() + 30);

I know that's not the right syntax, but I'm not sure how to say the current date plus 30 days.

Thanks!

2 REPLIES 2

jason_petty
Tera Expert

You could either use something different found in this document:
http://wiki.servicenow.com/index.php?title=Embedded:GS_Date_Time_Table

or for javascript you could do this:

var time = new Date();
newDate = time.setDate(d.getDate()+30);
gr.addQuery('valid_to', '>=', newDate);


JonathanJacob
Mega Sage

From Jason's post:

http://wiki.servicenow.com/index.php?title=GlideSystem_Date_and_Time_Functions#daysAgo.28int.29

Use the "daysAgo(int)"
var gr = new GlideRecord('kb_knowledge');
gr.addQuery('valid_to', '>=', gs.daysAgo(-30));