?
Solved

Help displaying time retrieved from a database field

Posted on 2004-10-15
10
Medium Priority
?
217 Views
Last Modified: 2010-03-31
I have a SQL 2000 database that in one of my columns I record a date and time. The sql format looks like:

10/15/2004 8:00:00 AM

When I retrieve this data to view in a JSP page I get:

Fri Oct 15 00:00:00 EDT 2004

I am not concerned with formatting right now as I have that much figured out but what my issue is I need the actual hh:mm:ss that were entered into the database to display. For some reason my time is reset to midnight regardless of the entry I make.

My current display is without formatting but this is what I will use to just display the time entered:

<% SimpleDateFormat dt = new SimpleDateFormat ("hh:mm:ss a"); %>
<td><%=dt.format(the.Rider(getArrivalTime())%></td>

This works fine in displaying the time but it always reads 12:00:00 AM regradless of the entry in the database.

Any suggestions on where I could be going wrong in retrieving the time?

RCMB

0
Comment
Question by:rcmb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 20

Expert Comment

by:Venabili
ID: 12318505
Hi rcmb,
How you read it from the database? And what type is the column in the database?
0
 
LVL 12

Author Comment

by:rcmb
ID: 12318563
This is the line that actually reads from the database

Date tmpArrivalTime = ConvertDate.SqlDateToUtilDate(rs.getDate("arrival_time"));
this.setArrivalTime(tmpArrivalTime);

The column in SQL is a shortdatetime

RCMB
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12318948
<td><%=dt.format(the.Rider(getArrivalTime())%></td>

isn't valid java...

what's "the.Rider" do?  And there aren't enough ')'s
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Author Comment

by:rcmb
ID: 12319343
The the.Rider is a vector that I used to gather the data from the sql query. Basically I have a sevlet that querys the database and then passes the data to a vector (the.Rider) and my jsp just grabs the data from the vector.

I am confused on the "isn't valid java" because it certainly works in displaying the information.

RCMB
0
 
LVL 12

Author Comment

by:rcmb
ID: 12319385
I also understand there are many ways "to skin the cat" in java. This is a simple jsp that just pre-populates a form so the user can update some data. If the time comes back as 12:00:00 AM vice the actual time then editing the information will do no good. The correct time will be recorded, as the system does now, but it never gets displayed.

RCMB
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12319470
> I am confused on the "isn't valid java" because it certainly works in displaying the information.

But there aren't enough closing braces...

 <td><%=dt.format(the.Rider(getArrivalTime())%></td>
..............................^..............^.......................^

3 opening ones...

 <td><%=dt.format(the.Rider(getArrivalTime())%></td>
........................................................................^^

2 closing ones...

plus..  how is:

 <td><%= dt.format( Vector( getArrivalTime() ) %></td>

supposed to work? (which is pseudocode as to what your function is trying to do)  Maybe I am just getting confused though...  sorry if this is true

Back to my own SQL hell for me ;-)

Good luck!

Tim
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 12320779
Hi rcmb,
It seems to me that there is a problem in your conversion.

> Date tmpArrivalTime = ConvertDate.SqlDateToUtilDate(rs.getDate("arrival_time"));

Btw, why are you doing a conversion? java.sql.Date extends java.util.Date so there is no need to convert.

What is the field type in the database for the arrival_time? If it is DATE, then that is where the problem is as that data type only stores a date, no time.

Consider using TIMESTAMP instead. SQL Server's DATETIME is a bad choice as it is SQL Server specific.

Cheers!

\tt
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 12324737
and getDate() will only return the date portion regardless of whats in the database.
use getTimestamp() instead.
0
 
LVL 12

Author Comment

by:rcmb
ID: 12324832
getTimestamp was the answer. I did not need to convert anything else.

Thanks for the help.

RCMB
0
 
LVL 92

Expert Comment

by:objects
ID: 12324838
:)
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month12 days, 8 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question