Get coerced into date error when trying to get a the vlaue from datetimeinput component

startDate = self.getSibling(‘StartDate’).props.formattedValues.date
endDate = self.getSibling(‘EndDate’).props.formattedValues.date
newdate = system.date.addDays(startDate,5)

props.formattedValues.date is of type string while system.date.addDays() expects a date as the first argument. You will have to parse it into a date before trying to use it, assuming you are using the default format from the datetime input it would look like this:

newDate = system.date.addDays(system.date.parse(startDate,'MMM d, YYYY'),5)

If you’ve changed the format on props.formattedValues.date, then just make sure the second argument in system.date.parse() is the correct format for what is being returned from that property.

It would be more robust to use:

startDate = system.date.fromMillis(self.getSibling('StartDate').props.value)
endDate = system.date.fromMillis(self.getSibling('EndDate').props.value)

Now you can directly manipulate them with system.date functions. You can also set props.value = system.date.toMillis(startDate) to change the date, if desired.

2 Likes