I am working on a project where I need to collect data from an API, store them in a matrix and set that data in a Google Sheet using the Google-Sheets-APIv4 with Node.js. Two key in that API are object.start_date and object.end_date which return date strings in the format for e.g "2021-09-22" ie. yyyy-mm-dd. I want to convert that date to dd/mm/yyyy format. The function I have implemented for the same is:
function changeDateFormat(dateString){
let a=dateString.split('-');
let t=a[0];
a[0]=a[2];
a[2]=t;
//console.log(a.join('/'));
return `${a.join('/')}`;
}
The code works fine and I have used it in the manner shown below:
let checkin=`${changeDateFormat(`${tenancy.start_date}`)}`;
console.log(checkin);
let checkout=`${changeDateFormat(`${tenancy.end_date}`)}`;
console.log(checkout);
tenancy in the code above is an object. The output that I get in the console is
which is the desired format, which shows that algorithm for changing date is working fine too.
Also, my code for adding the data in the sheet is
await googleSheets.spreadsheets.values.append({
auth,
spreadsheetId,
range:"MySheet!A2:AC",
valueInputOption:"USER_ENTERED",
resource: {values : newData}
/*newData is a 2-D array where each row has several data fields in the form newData[i]=[propertyName,id,......,check-in,checkout,.......]*/
});
However, when I add the data in the sheet, the date fields are entirely jumbled up where some have the desired dd/mm/yyyy format while others have the same yyyy-mm-dd format as shown in the image 
I am not being able to solve the problem as I cannot find any error in the code either but the output is completely jumbled as it's working in some cells but not working in other cells. What might be a possible workaround for this problem? I will gladly provide any other information or data regarding the problem or my code if needed. Thanks!