You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Legolas Woodland <le...@gmail.com> on 2006/01/23 09:59:53 UTC
How i can have a timeStamp wich point to 30 days ago
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.
Re: How i can have a timeStamp wich point to 30 days ago
Posted by Kristian Waagan <Kr...@Sun.COM>.
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.
>
>
>
Hi again,
You can also do this in Derby with the JDBC escape syntax.
Example from ij:
ij> VALUES CURRENT_TIMESTAMP;
1
--------------------------
2006-01-24 01:58:18.118
1 row selected
ij> VALUES {fn TIMESTAMPADD( SQL_TSI_DAY, -30, CURRENT_TIMESTAMP)};
1
--------------------------
2005-12-25 01:58:25.009
1 row selected
ij>
More info can be found here:
http://db.apache.org/derby/docs/dev/ref/rrefjdbc88908.html
--
Kristian
Re: How i can have a timeStamp wich point to 30 days ago
Posted by Kristian Waagan <Kr...@Sun.COM>.
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