Answer the question
In order to leave comments, you need to log in
How to understand that the entered value is a date?
There is a cell in the Google Sheet where users enter the date of birth of customers.
In 95% of cases, they record either February 25, or February 25 or February 25, 1980.
Through Google Script, I then transfer the entered value to another table and set a single format along the way
var birthday1 = ss1.getRange("D8").getValue();
var birthday = Utilities.formatDate(birthday1, "GMT+3", "dd-MM-yyyy")
Answer the question
In order to leave comments, you need to log in
The question is more for JavaScript, not for Google Apps Script.
Check for the presence of something in a variable, and then check if that variable has a getTime
.
function isDate(value){
return value && value.getTime;
}
function isDate(date){
return date instanceof Date && !isNaN(date.valueOf());
}
var birthday1 = ss1.getRange("D8").getValue();
var birthday = isDate(birthday1) ?
Utilities.formatDate(birthday1, "GMT+3", "dd-MM-yyyy") :
undefined;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question