Reputation: 99
I create a table by pulling data into the web application with the following code. The dates in the first column of the table ("r [0]") come to the number format. How can I convert the number format to date format as below? Number: 44346 To: 30.05.2021 or 30.05.2021 - 23:59:10
google.script.run.withSuccessHandler(generateTable).getTableData(username);
function generateTable(dataArray)
{
var tbody = document.getElementById("table-body");
dataArray.forEach(function(r){
var row = document.createElement("tr");
for(i=0; i<14; i++) {
var col = document.createElement("td");
col.textContent = r[i];
row.appendChild(col);
}
if(r[13] == "ONAYLANDI")
row.style.backgroundColor = "#0EE600";
tbody.appendChild(row);
});
}
Upvotes: 0
Views: 448
Reputation: 99
When I convert it to date format like in the image, it does not show the table data on the Web page. The codes related to data extraction are as follows.
// MACRO PAGE
function getTableData(username) {
var vs = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/1nRGsoyU70SZ7CwZKzHBhHEA92PhllqnsStpTPgocd3Q/').getSheetByName('Rapor GEÇMİŞ');
var data = vs.getRange(2, 1,vs.getLastRow()-1, 14).getValues().reverse().filter(function(item) { return item[7]=== username; });
console.log("Başarılı "+username);
return data;
}
// JS PAGE
google.script.run.withSuccessHandler(generateTable).getTableData(username);
function generateTable(dataArray)
{
var tbody = document.getElementById("table-body");
dataArray.forEach(function(r){
var row = document.createElement("tr");
for(i=0; i<14; i++) {
var col = document.createElement("td");
col.textContent = r[i];
row.appendChild(col);
}
if(r[13] == "ONAYLANDI")
row.style.backgroundColor = "#0EE600";
tbody.appendChild(row);
});
}
Web page result
When I convert the date to text format, it displays it on the web page (For example, text format "20.05.2021"). But when I convert it to date format as a numeric expression, it doesn't show. (For example number format "44336", date format "20.05.2021")
Upvotes: 1