473,395 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 9746
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

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

Similar topics

3
by: Ric | last post by:
I am using crystal reports to attempt to extract information from this database but I need to know which records were last updated. I have managed to find a field in Oracle and its value is based...
1
by: Schorschi | last post by:
Is there a better way to get the date/time from VB .NET into an Access MDB than "#" & Now & "#"? I have a standard date/time field in a table in a MDB file. And the '#' trick works, but seems...
7
by: Jerome | last post by:
Hallo, I know a lot has already been told about date/time fields in a database but still confuses me, specif when dealing with SQLserver(Express). It seems that sqlserver only accepts the date in...
2
by: markric | last post by:
I recently posted this message to microsoft.public.dotnet.framework.aspnet.webservices, but received no response, so I'm trying here in this group. I could really use some feedback. I'm working...
0
by: antonyliu2002 | last post by:
I am having a hard time connecting to an oracle database from within Visual Web Developer (VWD) 2005 Express Edition. Check out the screen snap shot here: ...
4
by: sbowman | last post by:
I have a table with help desk ticketing information. There is a Date/Time open, Date/Time closed field both formatted as: MM/DD/YYYY hh:nn:ss I need to calculate the difference between these two...
1
by: Bill | last post by:
We have a corporate database that was upgraded to Oracle 10 and I can no longer link to or query a table that contains a Time Stamp field with Access 2003. I've tried the Microsoft ODBC driver and...
4
by: SilentThunderer | last post by:
Hey folks, Let me start out by letting you know what I'm working with. I'm building an application in VB 2005 that is basically a userform that employees can use to "Clock in". The form...
1
by: 6afraidbecause789 | last post by:
Hi - I am using a Date/Time Picker popup form for users to choose a a date and time for use on a separate entry form. The date/time on the entry form is actually entered automatically as a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.