Java.sql.Timestamp question

Hi All,

I store a date and time in a SQL Database to act like a timestamp on when a record was input.

However when I try to retrieve this, I get a one hour difference all the time!

I used the [resultset].getTimestamp() method and it didn't work when I assigned the value to a java date or a java timestamp. It's always one hour behind when I retrieve it.

Any help would be great thanks!

Illu

[431 byte] By [Illua] at [2007-11-27 10:47:57]
# 1

How do you insert the timestamp value when you create/update the record?

Sounds like a Daylight Saving TIme problem.

malcolmmca at 2007-7-28 22:23:21 > top of Java-index,Java Essentials,Java Programming...
# 2

Hi Malcolm, cheers for the reply!

It does indeed look to be a daylight savings time problem. When I unclick the "auto adjust" checkbox on the computer's settings, the time is displayed correctly in the system.

As for the date/time, it is set in the stored procedure using the SQL getdate() method.

Do you know of a work around besides turning off the daylight savings time?

Thanks,

Illu

Illua at 2007-7-28 22:23:21 > top of Java-index,Java Essentials,Java Programming...
# 3

Here's my two cents worth of advice.

As a general rule, you should only store date in a database table, not date and time unless you really need to know the time too.

If you store the date and time, store the GMT time. Therefore (I believe) you dont have daylight saving time or timezone infomration attached to it.

When you retrieve the date/time, convert it to the correct daylight saving time and timezone for the locaiton that the person's computer is at that is looking at it (assuming his location observes daylight saving time). See 'java locale' to automatically convert the time to his timezone and weather to apply daylight saving time or not.

Also, when you get the current date time from your application running on the server, typically the date/time you get back is adjusted for daylight saving time and timezone where the server is. If you use Calendar calendar.getInstance(), I believe there may be an additional function (something like calendar.getGMTtime() ) to obtain the GMT time from that calendar.

George123a at 2007-7-28 22:23:21 > top of Java-index,Java Essentials,Java Programming...
# 4

Could be a discrepancy between the locale settings on youir client machine and the database server.

malcolmmca at 2007-7-28 22:23:21 > top of Java-index,Java Essentials,Java Programming...