I am using Dialogflow to pass the dateofbirth and convert it into ISO format using a particular function written in helperfile in webhook end.
I am trying to call a function in a helper file that converts the date of birth to ISO format and return the date in Javascript.
But it gives the result as Promise {2020-01-20:00:00:00} instead of the actual value.
The code in the helper file is given below:
const formatdob = async (df,globalParameter,dob) => { //birthDate should be in mm/dd/yyyy format
try {
console.log("globalParameter",globalParameter);
let dob = df._request.queryResult.queryText // Capturing the input from user
globalParameter["dob"]=dob;
if(dob.length!=0){ //function to convert into a ISO format
const d = new Date(dob);
return Date(
Date.UTC(
d.getFullYear(),
d.getMonth(),
d.getDate(),
d.getHours(),
d.getMinutes(),
d.getSeconds()
)
).toISOString();
}
}
catch (err) {
console.log(err)
throw err;
}
};
module.exports = formatdob;
I call the function using
dob= formatdob(df, globalParameter,dob);
console.log("dob",dob);
When I print the value,I get :
dob Promise { '2020-01-01T00:00:00.000Z' }
I want only the value to be printed.I am a beginner to Javascript . I also tried using await keyword while calling the function but it returned the same result...Could you please help me out with this?