In below code
- on subtracting date from a date giving this error
"The operator - is undefined for the argument type(s) java.util.Date, java.util.Date" variable currentDate is a
String; why I couldn't save it inDatevariable like thisDate currentDate = ddmmyy.format(new Date());, does.formatfunction returnsString?public class AgeCalculator { public static SimpleDateFormat ddmmyy=new SimpleDateFormat("dd/mm/yyyy"); public static void main(String[] args) throws Exception { String dob = "05/01/1993"; Date mod_date = ddmmyy.parse(dob); String currentDate = ddmmyy.format(new Date()); Date mod_currentDate = ddmmyy.parse(currentDate); int days = mod_currentDate-mod_date; } }