Display Quarter number based on date in Year

chanikya
Kilo Sage

1.Quarter number

2.Current number

Display Quarter number based on date

Ex: Jan   to march   Between related dates Display Quarter -1

April to June Between related dates Display Quarter -3 etc.

Ex:

now Current date: 2017-01-20       week: Quarter-1;

now Current date:2017-05-14           week: Quarter-2

1 ACCEPTED SOLUTION

remove current.update()



var check= current.u_another_open;


var test = new GlideDateTime(check);


var mn = test.getMonth();


var quar = Math.ceil(mn/3);


gs.log('hellosssssss'+quar);


current.u_dateee=quar;




find_real_file.png


View solution in original post

37 REPLIES 37

Hi Harsh Vardhan,



i got the result, i have changed my Time Zone now it is working fine



find_real_file.png





find_real_file.png


Gowrisankar Sat
Tera Guru

Hi,



Try this code:



  1. var gDate = new GlideDate();  
  2. gDate.setValue('2017-08-23');  
  3. var quarter = 'Quarter-' + (Math.floor((gDate.getMonth() - 1) / 3) + 1) ;  


Hi Gowrisankar,



Script is showing error,


divya mishra
Tera Guru

var gdt = new GlideDateTime();


var month = gdt.getMonth();


gs.print(month);


if((month==1) ||(month==2) ||(month==3) ||(month==4)){


gs.print("Quarter::1");


}


else if((month==5) ||(month==6) ||(month==7) ||(month==8)){


gs.print("Quarter::2");


}


else{


gs.print("Quarter::3");


}


Hi Divya,



If your fiscal year aligns with the calendar year, you can simplify that down to:



var gdt = new GlideDateTime();


gs.print("Quarter::" + parseInt(gdt.getMonthLocalTime()/3));




Thanks,


-Brian




Edit:   I missed using Math.ceil() to round up, thanks to others who pointed that out.