djechlin djechlin - 1 month ago 4x
SQL Question

Java SQL subtract an hour from date

I need a

value corresponding to one hour ago. I have a few date related things happening here so it's important that the current time is sampled only once and the rest of the code uses that same time. As far as setting a
based on current time in ms.

Manipulating the
object seems really klunky since I have to do things like add and subtract time to the calendar, which modifies it, so then I would have the lovely pleasure of either cloning myself a copy first or toggling its value around.


Simply subtract an hour off of the current time in milliseconds when making your timestamp (1 hour = 60 * 60 * 1000 ms)

Timestamp oneHourAgo = new Timestamp(System.currentTimeMillis() - (60 * 60 * 1000));