Link to home
Start Free TrialLog in
Avatar of xandrr
xandrr

asked on

jsp date format

We just started programming jsp and I have a basic question. I'm retrieving records from a table and one of the columns is a db2 date field. When I print out the data value (rs.getString("rdate")) it reads as follows:
2001-07-16 13:00:04.000000

I needed to format the date on the jsp page to read as something without the time. I know there is date formatting classes but for some reason it won't let me feed it a string...what code should i use to format this string? (how do i convert it into a date, etc?)

thanks ahead of time.
Avatar of Sumir
Sumir

take a look at java.sql.ResultSet  getDate(java.lang.String columnName) method

It returns a java.sql.Date.  (which is a child of the java.util.Date)

so you can do cool stuff like

Date myDate;
Calendar cal = Calendar.getInstance();  // current date

myDate = rs.getDate("rdate");
cal.setTime(myDate);  // sets the calendar to the retrieved time

// now you can use all of the cool Calendar methods.

 


ASKER CERTIFIED SOLUTION
Avatar of black
black

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why don't you just read the date part of the timestamp in your SQL?

Select date(rdate) from yourtable ...
by using the TO_CHAR() function you can change the sql call to format the date for you:

for example:  SELECT TO_CHAR(SYSDATE, 'Month DD, YYYY') FROM....

will return:  September 25, 2001
mkowales, there isn't a function called TO_CHAR() in DB2. Please read the guideline below on proposing answers.