469,270 Members | 1,146 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Retreiving Date/Time from a Date field in Oracle database

I am trying to retreive a string in this format dd-MM-yyyy hh:mm:ss a from Oracle database from the column of type Date which has value 10/09/2007 07:11:16

Date strfinaldate = new java.util.Date(rs.getTimestamp(10).getDate()+rs.ge tTimestamp(10).getTime());

SimpleDateFormat sf = new SimpleDateFormat ("dd-MM-yyyy hh:mm:ss a");
String formatteddate = sf.format(strfinaldate );

But I am getting the o/p as 10-09-2007 12:00:00 am

Please tell me how do I get the exact date/time

Thanks
Sep 20 '07 #1
9 9371
r035198x
13,262 8TB
I am trying to retreive a string in this format dd-MM-yyyy hh:mm:ss a from Oracle database from the column of type Date which has value 10/09/2007 07:11:16

Date strfinaldate = new java.util.Date(rs.getTimestamp(10).getDate()+rs.ge tTimestamp(10).getTime());

SimpleDateFormat sf = new SimpleDateFormat ("dd-MM-yyyy hh:mm:ss a");
String formatteddate = sf.format(strfinaldate );

But I am getting the o/p as 10-09-2007 12:00:00 am

Please tell me how do I get the exact date/time

Thanks
You can pass a Timestamp to the format method of the SimpleDateFormat class. Try that and see if you get the correct thing.
Sep 20 '07 #2
I tried doing with passing the timestamp object but still getting the same o/p.
Also I tried to print this value :

String cal = ""+tsdate.getHours()+tsdate.getMinutes()+tsdate.ge tSeconds();
where tsdate is the timestamp object.

Its showing as 000

Can anyone tell me why I getting this output though in databse it is showing as
Sep 20 '07 #3
r035198x
13,262 8TB
I tried doing with passing the timestamp object but still getting the same o/p.
Also I tried to print this value :

String cal = ""+tsdate.getHours()+tsdate.getMinutes()+tsdate.ge tSeconds();
where tsdate is the timestamp object.

Its showing as 000

Can anyone tell me why I getting this output though in databse it is showing as
If the column data type is Date, then you should be using rs.getDate to extract the date.
Sep 20 '07 #4
If the column data type is Date, then you should be using rs.getDate to extract the date.
I have even tried this way -
Date strfinaldate =rs.getDate(10);

SimpleDateFormat sf = new SimpleDateFormat ("dd-MM-yyyy hh:mm:ss a");
String formatteddate = sf.format(strfinaldate );


But still getting the same o/p as before
Sep 20 '07 #5
r035198x
13,262 8TB
I have even tried this way -
Date strfinaldate =rs.getDate(10);

SimpleDateFormat sf = new SimpleDateFormat ("dd-MM-yyyy hh:mm:ss a");
String formatteddate = sf.format(strfinaldate );


But still getting the same o/p as before
Did you try to retrieve the date using overloaded getDate method that takes a Calendar as well?
Perhaps your driver is returning the wrong date then
Sep 20 '07 #6
r035198x
13,262 8TB
Just thought about it a bit more.
You have an Oracle Date column that's storing both date and time.
You want to retrieve both the date and time fields.

So in your sql that retrieves the date, cast the Date to Timestamp using Oracle's TO_TIMESTAMP function then use rs.getTimeStamp to get both the date and time values. Tell us how that goes.
Sep 20 '07 #7
Just thought about it a bit more.
You have an Oracle Date column that's storing both date and time.
You want to retrieve both the date and time fields.

So in your sql that retrieves the date, cast the Date to Timestamp using Oracle's TO_TIMESTAMP function then use rs.getTimeStamp to get both the date and time values. Tell us how that goes.

Thanks a lot !!! I tried with oracle's to_char function in the query .
I could then get the exact value .
Sep 20 '07 #8
r035198x
13,262 8TB
Thanks a lot !!! I tried with oracle's to_char function in the query .
I could then get the exact value .
So the TO_TIMESTAMP function didn't work but the TO_CHAR function worked?
Sep 20 '07 #9
So the TO_TIMESTAMP function didn't work but the TO_CHAR function worked?
I didn't try with TO_TIMESTAMP .
Sep 20 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Schorschi | last post: by
7 posts views Thread by Jerome | last post: by
2 posts views Thread by markric | last post: by
4 posts views Thread by sbowman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.