new GlideDateTime().getDate(); this is giving complete date in" YYYY/MM/DD" format, I want only month and year in "MM/YYYY" this format .....what is script for this.

animesh3
Kilo Contributor

 new GlideDateTime().getDate(); this is giving complete date in" YYYY/MM/DD" format, I want only month and year in "MM/YYYY" this format .....what is script for this

5 REPLIES 5

Voona Rohila
Tera Patron

Hi animesh

Try this code to get month and year seperately.

var x= new GlideDateTime().getDate();
var year = x.getYear();
var month = x.getMonth();

 

Yes you can also use getByFormat as suggested by monica

monicaa
Tera Contributor

Hello Animesh,

Try using below code:

var a = new GlideDateTime().getDate();

a.getByFormat('MM/YYYY');

Ankur Bawiskar
Tera Patron

Hi,

this should work

var gdt = new GlideDateTime();
var todayDate = new GlideDate();
todayDate.setValue(gdt.getLocalDate());

var myFormat = todayDate.getByFormat("MM/yyyy");
gs.info("My format->" + myFormat);

Output:

find_real_file.png

Regards
Ankur