HI. Ok, real green question, and this even after I've looked through the forums for how to format a date returned from SQL. What I need is clarification really. Is this right? Or is there a better way to do this?
Many thanks... BTW... I'm about 1/4 of the way through my first JSP/Bean project...converting a ColdFusion app...it's been great and I'm learning a huge amount. Byron [This message has been edited by Byron Bignell (edited October 05, 2001).]
Here is one way to format a date returned from sql queries: // execute sql statement ResultSet rs = stmt.executeQuery(queryString); String[] hist = null; int idx = 1; hist[0] = "Date\Type"; // get resultset while (rs.next()) { Date tdate = rs.getDate("tdate"); String typetransaction = rs.getString("typetransaction"); hist[idx] = tdate + typetransaction; idx++; } You can then display the hist array into a component, perhaps a JList or JTextArea.
HI. I edited the code bit... I'm having this problem formatting the date field of a SQL record set to a nice looking date in the JSP template... It works just fine if I use an actual date...but if I try to parse the datetime from an ODBC/JDBC recordset I get an unparable string...or something equally as nasty. In the end I just need to be able to make this: 2002-01-10 00:00:00.0 into Jan 10 2001 in a JSP template. Byron
Got it! Got it! (sound of palm smacking forhead!) //first, don't just get the string as a string, get it as a date... Date mydate = qryItems.getDate("TargetDate"); //after that is all gets easier... SimpleDateFormat sdf = new SimpleDateFormat ("dd-MMM-yyyy"); String thedate = sdf.format(mydate); out.println(thedate); Major sigh of relief here...tome for that beer and some chips! Byron
It will give me the powers of the gods. Not bad for a tiny ad:
Gift giving made easy with the permaculture playing cards