Scripting help- getting the date in yyyy-mm-dd format

chidanandadhath
Kilo Guru

I have the below script where I'm getting first and last date of the month but not in yyyy-mm-dd format, 

var nowDateTime = new GlideDateTime('2019-05-10');
var date = nowDateTime.getDate();
var month = date.toString().split("-")[1];
var year = date.toString().split("-")[0];
var FirstDay = new Date(year, month-1, 1);
var LastDay = new Date(year, month, 0);
gs.info(FirstDay);
gs.info(LastDay);

 

Output:

*** Script: Wed May 01 2019 00:00:00 GMT-0700 (PDT)
*** Script: Fri May 31 2019 00:00:00 GMT-0700 (PDT)
1 ACCEPTED SOLUTION

Nirosha Uddandi
Kilo Guru

hi ,try with below code

var nowDateTime = new GlideDateTime('2019-05-10');
var date = nowDateTime.getDate();
var month = date.toString().split("-")[1];
var year = date.toString().split("-")[0];
var FirstDay = new Date(year, month-1, 1);
var LastDay = new Date(year, month, 0);
var first= new GlideDateTime(FirstDay);
var last = new GlideDateTime(LastDay);
gs.info(first);
gs.info(last);

View solution in original post

7 REPLIES 7

Nirosha Uddandi
Kilo Guru

hi ,try with below code

var nowDateTime = new GlideDateTime('2019-05-10');
var date = nowDateTime.getDate();
var month = date.toString().split("-")[1];
var year = date.toString().split("-")[0];
var FirstDay = new Date(year, month-1, 1);
var LastDay = new Date(year, month, 0);
var first= new GlideDateTime(FirstDay);
var last = new GlideDateTime(LastDay);
gs.info(first);
gs.info(last);

I'm getting output like below, how to get only date not time

 

*** Script: 2019-05-01 07:00:00
*** Script: 2019-05-31 07:00:00

 

sorry i forgot to mention use this

gs.info(first.getDate());

gs.info(last.getDate());

to print