none
Dutch date format in Excel RRS feed

  • Question

  • Hello,

    The next code give's me the correct date as string in Excel. How can i get Excel to regonize the date as date?

    There is no dteDatum.toLocaleDate

    Excel.run(function (ctx) {
    
    
                var shtBron = ctx.workbook.worksheets.getActiveWorksheet();
                
                return ctx.sync()
                    .then(function () {
    					
    						var strDatum = new String("29-12-15");
    						strDatum =strDatum.split("-");
    						
    						var Dag = new Number(strDatum[0]);
    						var Maand = new Number(strDatum[1]-1);
    						var Jaar = new Number("20" + strDatum[2]);
    						
    						var dteDatum = new Date(Jaar, Maand, Dag);
    					
    					 	shtBron.getRange("A1").values = dteDatum.toLocaleDateString("nl-NL");
    					}
                    )
                    .catch(function (error) {
                        console.log("Fout: " + error);
                    });
            });

    Thursday, July 21, 2016 10:08 AM

Answers

  • function getFormattedDate(date) {
    	var year = date.getFullYear();
    	var month = (1 + date.getMonth()).toString();
    	month = month.length > 1 ? month : '0' + month;
    	var day = date.getDate().toString();
    	day = day.length > 1 ? day : '0' + day;
    	return month + '/' + day + '/' + year;
    }
    this works for me.
    • Marked as answer by Pacecal Thursday, July 21, 2016 2:50 PM
    Thursday, July 21, 2016 2:50 PM