I am trying to create a udf to take two strings as parameters; one in DD-MM-YYYY format (e.g. "14-10-2019") and the other in float format (e.g. "0.000"). I want to convert the float-like string to an int and add it to the date object to get another date which I want to return as a string.
def getEndDate = udf{ (startDate: String, no_of_days : String) =>
val num_days = no_of_days.trim.toInt //Converts the String value to Integer
val date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse(startDate) //Parses the string date to timestamp
calObj.setTime(date) //Sets the calendar object instance
calObj.add(Calendar.DAY_OF_MONTH, num_days) //Adds the number of days to the start date
val endDate = calObj.getTime().toString //Gets end date in string format
endDate
}
When trying to run this, I am getting the following error:
Caused by: java.lang.NumberFormatException: For input string: "0.000"