Skip to Content

Convert Date Field in an Object Array of XSJS

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 ?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Oct 30, 2017 at 02:16 PM

    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

    Add comment
    10|10000 characters needed characters exceeded