Skip to Content
0
Jun 20, 2018 at 09:29 AM

How to extract month from Date

361 Views

Hi Experts,

I have trying to extract month from date. Below is my code for my xsjs file:

var conn = $.db.getConnection();
var d = new Date();
//YYYY-MM-DDThh:mm:ss
var output = d.getFullYear() + '-' +
('0' + (d.getMonth()+1)).slice(-2) + '-' +
('0' + d.getDate()).slice(-2) + 'T' +
('0' + d.getHours()).slice(-2) + ':' +
('0' + d.getMinutes()).slice(-2) + ':' +
('0' + d.getSeconds()).slice(-2);

var pstmt = conn.prepareStatement("SELECT \"date1\", \"date2\" FROM \"y\" where \"date1\" >'"+output+"'" );

pstmt.execute();

var a = "TEST";
var rs = pstmt.getResultSet();
if(!rs.next()){
$.response.setBody("got nothing");
}else{
var start=rs.getString(1);
// var month=start.getMonth();
//var month= to_char(to_date(y.date1,'dd-MM-yyyy'),'MM')
//var month=EXTRACT(MONTH FROM y.date1);
// $.response.setBody(rs.getString(1)+ rs.getString(2));
$.response.setBody(month); }

I am always getting the error getMonth() is not a function.
Could you please tell me how can I follow up on this?