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

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


Something like this works too...



var das = gs.daysAgoStart(0);


das = das.split(" ");




var dae = gs.daysAgoEnd(0);


dae = dae.split(" ");




gr.addEncodedQuery("closed_atBETWEENjavascript:gs.dateGenerate('" + das[0] + "', '06:30:00')@javascript:gs.dateGenerate('" + dae[0] + "', '06:30:00')");









But I'll try yours because it's prettier  


And I like keeping encoded queries on a single line, even with javascript embedded (that way, you can use it in GQL).



BTW, if you want to use daysAgoStart(), I believe "yesterday" should be



gs.daysAgoStart(1)



Also to add to this, since some functions take the input in local time and output in GMT, I'd suggest testing some edge cases to make sure it's working as intended.


Well... just ran into something very confusing....   these gs.dateGenerate()'s are failing!



Here's the code that generates the gs.log()'s:



var das = gs.daysAgoStart(0);


das = das.split(" ");


gs.log("-}> gs.daysAgoStart(0): " + gs.daysAgoStart(0));


gs.log("-}> das[0]: " + das[0]);




var dae = gs.daysAgoEnd(0);


dae = dae.split(" ");


gs.log("-}> gs.daysAgoEnd(0): " + gs.daysAgoEnd(0));


gs.log("-}> dae[0]: " + dae[0]);




var bot = gs.beginningOfToday().slice(0, 10);


var boy = gs.beginningOfYesterday().slice(0, 10);


var bot2 = gs.beginningOfToday();


var boy2 = gs.beginningOfYesterday();




gs.log("-}> BOT: " + bot);


gs.log("-}> BOY: " + boy);


gs.log("-}> BOT2: " + bot2);


gs.log("-}> BOY2: " + boy2);




gs.log("-}> TODAY: " + gs.dateGenerate(gs.beginningOfToday().slice(0,10),'06:30:00'));


gs.log("-}> YESTERDAY: " + gs.dateGenerate(gs.beginningOfYesterday().slice(0,10),'06:30:00'));




gs.log("-}> TODAY2: " + gs.dateGenerate(das[0],'06:30:00'));


gs.log("-}> YESTERDAY2: " + gs.dateGenerate(dae[0],'06:30:00'));


















Now, here's the result:



find_real_file.png




Notice that all the gs.dateGenerate() calls are completely ignoring the second parameter!



Why?


That's the time zone. As I mentioned in the previous post, the inputs are in local time, the output in GMT. I see that you're in U.S. EDT, so 06:30 EDT = 10:30 GMT.



If that's the case, your output looks OK to me.