Monday, June 21, 2021

OIC JS - return last day

Object: Return last day of the month in this format yyyy-mm-dd

Js codes:

function returnLastDay(){

var date = new Date(), y = date.getFullYear(), m = date.getMonth();

var lastDate = new Date(y, m + 1, 0);

var day = lastDate.getDate();

var month = lastDate.getMonth() + 1;

var year = lastDate.getFullYear();

if ( parseInt(month) < 10 ) {

var newMonth = "0" + month;

}

else { 

var newMonth = month;

}

if ( parseInt(day) < 10 ) {

var newDay = "0" + day;

}

else { 

var newDay = day;

}

var lastday = year + "-" + newMonth + "-" + newDay;

return lastday;

}


Note

getMonth() method returns the months from 0 to 11. January is the 0 and February is 1 and so on...

firstDay = new Date(y, m, 1)

lastDay = new Date(y, m+1, 0)




No comments:

Post a Comment

Featured Post

OIC - how can I use XSLT functions to remove leading zeros from numeric and alphanumeric fields?

To remove leading zeros from an numeric field in Oracle Integration Cloud (OIC) using XSLT, you can Use number() Function The number() funct...