on 10-30-2017 1:00 PM - last edited on 02-04-2024 1:10 AM by postmig_api_4
Dear All,
I am using below code in my xsjs to read data from Hana View. In the ResultSet Object,
a) In records Resultset object, I have all date fields coming in with value as 2017-10-12T00:00:00:000Z.
b) And few garbage values.
How can I modify the date object to represent just dd-mm-yyyy and get rid of absurd entries please ?
XSJS Code currently :
var conn = $.hdb.getConnection();
str = "SELECT * FROM WHERE \"COMPANY_CD\"=? AND \"DOC_KEY\" =? AND \"SYSTEM_ID\"=? AND \"POSTING_DATE\" BETWEEN ? AND ?";
records = conn.executeQuery(str, company, key, applnid, startdate, enddate);
I tried doing the below in a loop to select Date field in records Object and manipulating it. But it gave me a Type Error that the Date field is Read-Only.
records[i].INVOICE_DATE = (records[i].INVOICE_DATE.toString()).split('T')[0];
Can you please help on how can I modify records JSON with right values (and also by avoiding garage values like (-000001-12-31T00:00:00.000Z) please ?
Hi Hari,
I create a function to get your right format.
function formatDate (input)
{
var d,m,y;
d= input.getDate();
if(Number(d)<10){
d= '0'+d;}
m = input.getMonth();
m= Number(m)+1;
if(Number(m)<10){
m= '0'+m;}
y= input.getFullYear();
return (d+'.'+m+'.'+y);
}
INVOICE_DATE = formatDate(records[i].INVOICE_DATE)
I hope that it will help you.
Best regards
Houssem
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Houssem,
Thank you for quick reply. "records" is an object array. It has several keys and Date is one among them.
So when I am trying to modify Invoice_Date with the new value and modifying it back in the array, it is giving me Type Error that "Invoice_Date" is Ready Only I am afraid.
Thanks
Yes you should create a new variable to store the new data.
Here an example.
Var NewArray = [];
for ( var i = 0 ;i<records.length ;i++)
{
entry= {}
entry.X = records[i]["X"]
entry.Y = formatDate(records[i]["Y"])
entry.Z = formatDate(records[i]["Z"])
entry.A=records[i]["A"]
entry.B =records[i]["B"]
output.NewArray.push(entry);
}
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.