Subject Re: [Firebird-Java] Inserting only date-part of timestam with Jaybird and Hibernate
Author Yves Glodt
Thanks Mark for your suggestions.

To get the desired result I used #3:

Date today = new Date();
java.sql.Date now = new
java.sql.Date(today.getYear(),today.getMonth(),today.getDay());

Only this gave me the expected result of having only dates in my timestamps.
(new java.sql.Date(System.currentTimeMillis()) resulted in having a
time-part stangely)

#1 was not doable since it's a legacy database which I work against.

Thanks and best regards!
Yves


On 16 November 2010 17:11, Mark Rotteveel <Avalanche1979@...> wrote:

> > Hi,
> >
> > I am not 100% sure this is related to Firebird/Jaybird, so forgive me in
> > case I'm wrong.
> >
> > I am inserting a row with hibernate, and for setting a date column
> > (Timestamp in sql) to today I use:
> >
> > record.setCreationDate( new java.util.Date() );
> >
> > This works generally, but includes the time-part (16.11.2010 15:27:24),
> > whereas I would only want the date (16.11.2010)
> >
> > Does anyone know how to fix this?
>
> There are a number of ways (in order of 'best' to 'worse'):
> 1) Use DATE as your column type if you are not interested in the time
> portion, not TIMESTAMP; TIMESTAMP is simply the wrong type for this
> 2) Set the time portions to zero
> 3) Use java.sql.Date, not java.util.Date (java.sql.Date does not store time
> portion)
> 4) Add a trigger to normalize the TIMESTAMP value by cutting off time
> information (eg by casting to DATE)
>
> Mark
> --
> Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!
> Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>


[Non-text portions of this message have been removed]