gs.dateGenerate using specific times between yesterday and today

xiaix
Tera Guru

I need to get a date range between 6:30am yesterday and 6:30am today.

I know I can do this:

closed_atBETWEENjavascript:gs.dateGenerate('2016-11-01','06:30:00')@javascript:gs.dateGenerate('2016-11-02','06:30:00')

But as you see I'm hard-coding the day/month/year.

I'm curious, will this work?

closed_atBETWEENjavascript:gs.dateGenerate(gs.daysAgoStart(0),'06:30:00')@javascript:gs.dateGenerate(gs.daysAgoEnd(0),'06:30:00')

1 ACCEPTED SOLUTION

drjohnchun
Tera Guru

Something like this may work:



closed_atBETWEENjavascript:gs.dateGenerate(gs.beginningOfYesterday().slice(0,10),'06:30:00')@javascript:gs.dateGenerate(gs.beginningOfToday().slice(0,10),'06:30:00')



Please feel free to connect, follow, mark helpful / answer, like, endorse.


John Chun, PhD PMP see John's LinkedIn profile


visit snowaid


View solution in original post

12 REPLIES 12

Yes, I glazed over your last sentence which you clearly explained this.   My apologies.  


I'm going to mark this correct.   The only thing is it has to be done in reverse:



closed_atBETWEENjavascript:gs.dateGenerate(gs.beginningOfToday().slice(0,10),'06:30:00')@javascript:gs.dateGenerate(gs.beginningOfYesterday().slice(0,10),'06:30:00')



For some reason I got tons of errors when I tried putting gs.beginningOfToday() first.   Switching the yesterday and today resolved it.



Thanks John for all your help!


According to http://wiki.servicenow.com?title=Operators_Available_for_Filters_and_Queries, the smaller value comes first for BETWEEN:



between[SLA due][between][Yesterday] and [Today]BETWEENsla_dueBETWEENjavascript:gs.daysAgoStart(1)@javascript:gs.daysAgoEnd(0)


As long as you're getting the expected results without errors, I'd say let's go with it.