1

I have a date and duration. I need to add the duration to date. Date's format is timestamp, duration's - Long (milliseconds). How can I wright criteria to deal this issue? Practically i have something like this: 03-17-2014 21:24:57 + 2523566;

Dante
  • 279
  • 1
  • 19
  • Use [Joda-Time](http://www.joda.org/joda-time/) or `Calendar` (or Java 8's new time API), for [example](http://stackoverflow.com/questions/21842934/how-to-add-days-to-java-simple-date-format/21842959#21842959) – MadProgrammer Aug 14 '14 at 08:39
  • use SimpleDateFormat to parse and convert your String to a Date, then create new Date from dt.getTime + ts – Scary Wombat Aug 14 '14 at 08:40
  • My dates and durations lays in SQL data base. I need to wright the query which wolud count it and extract to list. – Dante Aug 14 '14 at 08:42

1 Answers1

1

If you want to do it in Java and have a java.sql.Date and a long:

public java.sql.Date dateAdd(java.sql.Date inputDate, long duration)
{
    return new java.sql.Date(inputDate.getTime() + duration);
}

A java.sql.Timestamp can be used in place of a java.sql.Date in either the argument or the return value, if required.

user3757014
  • 222
  • 1
  • 3
  • Thank you, but it is not criteria query. To deal this problem in java i can with the help of simple day format and other tools. But i need criteria query. I have such task – Dante Aug 14 '14 at 09:02