on 06-20-2018 10:29 AM
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?
Hi Meghna,
what type has the column containing your date? Is it a String or a Date type?
In your coding (var start = rs.getString(1)) you are assuming it is a String. On a String you cannot call the function "getMonth". If it is really a String you have to first convert your String to a Date (depending on your format).
If the column has a Date type already, you should get the value from the result set using method "getDate" (e.g. var start = rs.getDate(1)). With that you get a Date reference on which you can execute function "getMonth".
Regards,
Florian
PS:
You are using the legacy $.db API. Maybe you can also check to switch to the new $.hdb interface which simplifies everything.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.