I want to check the first day of month and Day of that week

Sjoshi2
Mega Contributor

I wrote a code :

var gdt = new GlideDateTime();

var date = gs.beginningOfThisMonth(gdt);

gs.print(date);

*and I get a perfect result however when I check which day the date comes on it gives undefined answer. for this I used:

gs.print(date.getDayOfWeek());

* If I use getDayOfWeek() function separately it answers correct. however If I use it after beginningOfThisMonth it answers as undefined.

How day I check Day of first Day of Month?

1 ACCEPTED SOLUTION

Mihir Mohanta
Kilo Sage

Try below script



var date = gs.beginningOfThisMonth(gdt);


var gdt = new GlideDateTime(date);


gs.print(date);


gs.print(gdt.getDayOfWeek());




Thanks,


Mihir


View solution in original post

4 REPLIES 4

Mihir Mohanta
Kilo Sage

Try below script



var date = gs.beginningOfThisMonth(gdt);


var gdt = new GlideDateTime(date);


gs.print(date);


gs.print(gdt.getDayOfWeek());




Thanks,


Mihir


Thank you it is perfect


This works great, random question though, How does the compiler not throw an error since gdt isnt technically defined until the next line? It's kind of confusing. Thank you. 

Deepa Srivastav
Kilo Sage

Hi Shreya,



Define 'date' again as GlideDateTime object then use getDayOfWeek() function;


var newdate = new GlideDateTime(date);
newdate.getDayOfWeek();



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.



Thanks,
Deepa