Originally posted by Paul Campbell:
Insert into mytable (id, StartDate, enddate, duration)
VALUES (id, StartDate, endDate, (to_date(endDate,'date format of endDate') - to_date(StartDate,'date format of StartDate)))
This will work, but a much better route would be to do the calculation in Java and use a prepared statement. It makes you code portable and avoids the need to change things if the date format is changed.
Originally posted by Divya Gehlot:
But I dont want it in this way for calculation of number of days I have one java function( customised function to calculate number of days) want to use that.
In which case, assuming your database supports Java, you will most probably need to implement this query as a Java stored procedure in the database. I don't know if databases that support Java also support compilation on the fly from adhoc queries - you may want to check your database documentation. For what its worth, my personal preference would always be to do calculations in the application not the database.