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

Kalaiarasan Pus
Giga Sage

var dateObject = new GlideDateTime();


var today = (dateObject.getDate()).toString();


dateObject.addDays(-1);


var yesterday = (dateObject.getDate()).toString();


gs.print(today);


gs.print(yesterday);


Thanks for the reply, Kalaiarasan, but unfortunately that doesn't help me in this situation....   however, it appears to have helped jayachandran     In fact, it seems you're the only one who jayachandran seems to pay any attention to:



find_real_file.png


I apologise if I wasn't clear enough in my response and I should have added some statements to explain the solution.



But did you try to execute the script which I had provided ? Your question was specifically looking for function to return today's and yesterday's date ? Wasn't it ?



var dateObject = new GlideDateTime();


var today = (dateObject.getDate()).toString();


dateObject.addDays(-1);


var yesterday = (dateObject.getDate()).toString();


gs.print(today);


gs.print(yesterday);



Now the variable today and yesterday here stores the value you need. You just need to replace the variables in your code and it should work just fine. Correct me if I mistook your question


And my solution uses only uses out of the box methods that would provide an assurance to work even if you do any upgrade in future.