Legolas Woodland wrote:
Hi
Thank you for reading my post
how i can create a timestamp which point to 30 days ago ?
i mean a java.sql.Timestamp which point to 30 days ago , from current date.




Hello Legolas,

My answer is based on a few minutes of browsing in the Java API documentation (which can be found here by the way: http://java.sun.com/j2se/1.5.0/docs/api/), so it might be a bit inaccurate and there may be better ways.

You don't say if you want to do this in the database or in your application, but you can use GregorianCalendar. The general idea:

GregorianCalendar cal = new GregorianCalendar() // Use current time/date
// Do not use roll() for your case, but add().
cal.add(Calendar.DAY_OF_MONTH, -30);
        // OR
cal.add(Calendar.DAY_OF_YEAR, -30);
Timestamp stamp = new Timestamp(cal.getTimeInMillis());


There are a lot more knobs to turn in the calendar, if you should need that.



--
Kristian

Reply via email to